Rails no route matches with nested resources

爱⌒轻易说出口 提交于 2019-12-10 03:56:09

问题


I know this question comes up a lot with Rails, but I can't seem to get any of the previous answers to work for me.

MyApplication::Application.routes.draw do
  resources :matters do
    resources :issues
  end 

I'm getting the following routing error:

No route matches {:action=>"show", :controller=>"issues", :matter_id=>#<Matter id: 2, name: "Wilson", user_id: nil, created_at: "2011-03-23 18:19:40", updated_at: "2011-03-23 18:19:40">, :id=>nil}

I am trying to get the path like this:

<%= link_to issue.content, matter_issue_path(@matter, @issue) %>

When I run rake routes it shows that I have the path:

matter_issues GET  /matters/:matter_id/issues(.:format) {:action=>"index", :controller=>"issues"}

Any ideas why I'm getting this error? Thanks!


回答1:


Try matter_issues_path(@matter, @issue)

I always seem to run into these pluralization gotchas with Rails routing.



来源:https://stackoverflow.com/questions/5410215/rails-no-route-matches-with-nested-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!