2011-06-17 37 views
0

Rails noob here。我在rails 3应用程序中使用carrierwave,因此用户可以上传个人资料图片。我建立了一个单独的模型,控制器和视图(profile_pictures)来处理这个问题。为了避免犯错,我使用脚手架作为起点。轨道3中的路由错误应用程序

路由文件:

resources :profile_pictures 

耙路线:

edit_profile_picture GET /profile_pictures/:id/edit(.:format)   {:action=>"edit", :controller=>"profile_pictures"} 

链接edit.html.erb:

<%= link_to "profile picture", edit_profile_picture_path %> 

错误:

No route matches {:action=>"edit", :controller=>"profile_pictures"} 

Side Note:我经常遇到路线问题......它让我疯狂。我发现了许多关于将先前路由格式转换为rails 3路由的页面。有关于解释所有nubbies的路线的基本教程? ...最好使用rails 3格式,但以前的版本可以,如果有的话。

谢谢!

回答

1

尝试<%= link_to "profile picture", edit_profile_picture_path(@picture) %>

Becouse你有一个路线/profile_pictures/:id/edit,@picture ==:ID

3

所有的路由帮手首先是不工作,因为它期待一个对象或id作为呼叫的一部分,所以在这里你有:

<%= link_to "profile picture", edit_profile_picture_path %>

你需要有这样的:

<%= link_to "profile picture", edit_profile_picture_path(@user) %>

用户将成为您想要在个人资料图片控制器中使用的对象。在寻址路由时使用不带对象的编辑是常见的错误。