2

I'm not being able to redirect the user to the page I want after he creates a new "service" resource.

Here's the routes.rb:

resources :wsps do
    resources :services
end

The html form:

<%= form_for([@wsp,@service]) do |f| %>

Services_controller.rb:

 def new
    @wsp = current_wsp
    @service = @wsp.services.build
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @service }
    end  
  end

def create
    @wsp = current_wsp
    @service = @wsp.services.build(params[:service])
    if @service.save
        redirect_to wsp_service_path
    end
  end

The wsp_service_path goes to /wsps/1/services and the error:

No route matches {:action=>"destroy", :controller=>"services"}

What am I doing wrong? Why cant't I use "wsp_service_path"?

Thank you.

1 Answer 1

3

You can use wsp_service_path (while you should be use wsp_service_url since you are in a controller). All you are missing is arguments. wsp_service_path (or _url) are going to expect two arguments: a wsp and a service. Once you provide those two, it works.

redirect_to wsp_service_url(@wsp, @service) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.