Rails 3 nested routes controller access
I have a nested route as:
resources :wsps do
member do
get :location
开发者_Go百科 get :password
end
resources :services
end
I can access all the paths (e.g: new_wsp_service_path) via de services views and services controller, however, I cannot do the same using the wsp views. It says It not recognizes the action "new".
I'd like to know how can I use the new_wsp_service_path on the Wsps views as well.
I have tried to add this to the wsp controller show but still not fixes:
def show
@wsp = Wsp.find(params[:id])
@title = @wsp.name
@services = @wsp.services
@page_name = "overview"
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @services }
end
end
thanks.
Make sure you are passing a Wsp
object when you call the path helper.
Open up the rails console (rails c
) and try this::
app.new_wsp_service_path # => ERROR!
app.new_wsp_service_path(1) # => should work
@wsp = ... # get a Wsp record
app.new_wsp_service_path(@wsp) # => should work
I run into this error often when I forget to pass a record to the embedded route. If this doesn't solve your problem, please post the output of the commands above and also make sure your route is set up using rake routes | grep new_wsp_service
.
精彩评论