2011-06-17 36 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) %>

用戶將成爲您想要在個人資料圖片控制器中使用的對象。在尋址路由時使用不帶對象的編輯是常見的錯誤。