在我的申请,我有一个的RecipesController和CommentsController。所有评论都属于一个配方,可以投票。下面是从我的routes.rb片段:Rails的路由错误与嵌套资源
resources :recipes do
member do
put 'vote_up'
post 'comment'
end
resources :comments do
member do
put 'vote_up'
end
end
end
如果我运行耙路线,我发现在输出以下路线:
vote_up_recipe_comment PUT /recipes/:recipe_id/comments/:id/vote_up(.:format) {:action=>"vote_up", :controller=>"comments"}
的CommentsController有一个名为vote_up方法。
此外,链接到路线的作品(从我的观点)
<%= link_to 'Vote up', vote_up_recipe_comment_path(@recipe, comment), :method => 'put' %> <br />
但是,点击该链接上给了我以下错误:
Routing Error
No route matches "/recipes/7/comments/4/vote_up"
我缺少什么?我不知道如何调试,因为据我看到的路线应该匹配。
非常感谢,该诀窍。我确实删除了一些javascript文件。事后看来,这很明显,但它可能会花费我很长时间才能找到。 – 2010-11-02 10:54:17