2012-07-26 71 views
1

嘗試訪問<%= link_to('Edit registration',edit_user_registration_path)%>時出現以下錯誤。設計路由錯誤edit_user_registration_path

Routing Error 
No route matches {:action=>"edit", :controller=>"profiles"} 
Try running rake routes for more information on available routes. 

的routes.rb

xyz::Application.routes.draw do 

root :to => "home#index" 

resources :profiles 

devise_for :users 

authenticated :user do 
root :to => "home#index" 
end 
end 

我的路線如下:

root  /       home#index 
profiles GET /profiles(.:format)   profiles#index 
POST /profiles(.:format)   profiles#create 
new_profile GET /profiles/new(.:format)  profiles#new 
edit_profile GET /profiles/:id/edit(.:format) profiles#edit 
profile GET /profiles/:id(.:format)  profiles#show 
PUT /profiles/:id(.:format)  profiles#update 
DELETE /profiles/:id(.:format)  profiles#destroy 
new_user_session GET /users/sign_in(.:format)  devise/sessions#new 
user_session POST /users/sign_in(.:format)  devise/sessions#create 
destroy_user_session DELETE /users/sign_out(.:format)  devise/sessions#destroy 
user_password POST /users/password(.:format)  devise/passwords#create 
new_user_password GET /users/password/new(.:format) devise/passwords#new 
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit 
PUT /users/password(.:format)  devise/passwords#update 
cancel_user_registration GET /users/cancel(.:format)  devise/registrations#cancel 
user_registration POST /users(.:format)    devise/registrations#create 
new_user_registration GET /users/sign_up(.:format)  devise/registrations#new 
edit_user_registration GET /users/edit(.:format)   devise/registrations#edit 
PUT /users(.:format)    devise/registrations#update 
DELETE /users(.:format)    devise/registrations#destroy 
root  /       home#index 

感謝您的非常對你有所幫助!

+0

錯誤看起來像它來自edit_profile路線,而不是edit_user_registration路線。這應該是在編輯個人資料頁面,如果是的話,你可以告訴我們你如何鏈接到那裏? – 2012-07-26 09:29:11

+0

我從配置文件視圖中添加了一個鏈接,如下所示:<%= link_to'編輯註冊',edit_user_registration_path(current_user)%>' - 呈現的鏈接看起來像http:// localhost:3000/users/edit.10(with current_user )和http:// localhost:3000/users/edit(不含current_user)。我認爲設計是把配置文件控制器作爲資源......但如何解決這個問題?我用於編輯配置文件頁面的路徑是<%= link_to'編輯配置文件',edit_profile_path%> – 2012-07-26 11:03:30

回答

3
<%= link_to('Edit registration', edit_user_registration_path) %>. 

是不是被傳遞了一個我最好

<%= link_to('Edit registration', edit_user_registration_path(@user)) %>. 
+0

謝謝,這工作得很好! – 2012-07-27 15:10:40

0

的問題不是編輯註冊鏈接,原因是這樣在你的路線:

edit_profile GET /profiles/:id/edit(.:format) profiles#edit 

而鏈接到配置文件頁面:

<%= link_to 'Edit Profile', edit_profile_path %> 

edit_profile _path期待一個ID

您需要在您要編輯配置文件對象經過:

<%= link_to 'Edit Profile', edit_profile_path(@user) %> 

或者,如果你想配置文件對當前用戶只行動,在路線設置它.rb作爲單數資源:

resource :profile 
0

我有同樣的問題。通過編輯routes.rb解決它:

Rails.application.routes.draw do 
    if Rails.env == 'production' 
    default_url_options :host => "myserver.com" 
    else 
    default_url_options :host => "localhost:3000" 
    end