开发者

Nested Route link_to helper working in one place but not another

I have a nested routes problem that I can not figure out. I have an app that has nested routes like so:

resources :events do
  resources :sessions
end

I am trying to use the following link_to in my code:

<%= link_to "New Session", new_event_session_path %>

When I run rake routes, it will show the proper URL with a GET method existing:

new_event_session GET    /events/:event_id/sessions/new(.:format)      {:action=>"new", :controller=>"sessions"}

When I try to use the link_to in one place it works, when I try to use it in another place it does not, it instead will give me this error:

No route matches {:controller=>"sessions", :action=>开发者_如何学Python;"new"}

The only difference between the two files is the location of the files in the app (one is under views/events the other is under views/sessions and the url being called:

/events/1 --vs-- /events/1/sessions

I am still a noob with rails, so this is probably a stupid question, but I have hit a bit of a wall. Any help is appreciated.


You just need to pass event object to path helper:

new_event_session_path(@event)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜