开发者

Routing error in rails 3 app

开发者 https://www.devze.com 2023-03-14 04:17 出处:网络
Rails noob here. I am using carrierwave in a rails 3 app so users can upload a profile picture. I set up a separate model, controller and views (profile_pictures) to handle this. To avoid making error

Rails noob here. I am using carrierwave in a rails 3 app so users can upload a profile picture. I set up a separate model, controller and views (profile_pictures) to handle this. To avoid making errors i use scaffold as a starting point.

route file:

resources :profile_pictures

rake routes:

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

link to edit.html.erb:

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

error:

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

Side Note: I am constantly running into problems with routes... its driving me nuts. I've found numerous pages regarding conversion of prior routing format to ra开发者_JS百科ils 3 routes. Is there a basic tutorial on routes that explains all the nubbies? ... preferably in rails 3 format but a prior version is ok if that is all there is.

Thanks!!


First of all the route helper is not working because it is expecting an object or id as part of the call so where you have:

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

You need to have something like:

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

Where user would be the object that you'd want to use in your profile pictures controller. Using edit without an object is a common error when addressing routes.


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

Becouse you have a route /profile_pictures/:id/edit, @picture == :id

0

精彩评论

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