【问题标题】:devise routing error edit_user_registration_path设计路由错误edit_user_registration_path
【发布时间】:2012-07-26 09:14:07
【问题描述】:

我在尝试访问 时遇到以下错误。

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

非常感谢您的帮助!

【问题讨论】:

  • 错误看起来像是来自 edit_profile 路由,而不是 edit_user_registration 路由。这应该在编辑个人资料页面上吗?如果是这样,你能告诉我们你是如何链接到那里的吗?
  • 我从个人资料视图中添加了一个链接,如下 '' - 呈现的链接看起来像 localhost:3000/users/edit.10(带有 current_user)和 @ 987654322@(没有 current_user)。我认为设计将配置文件控制器作为资源......但是如何解决这个问题?我用于编辑个人资料页面的路径是

标签: ruby-on-rails routing devise


【解决方案1】:
<%= link_to('Edit registration', edit_user_registration_path) %>.

我没有被通过

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

【讨论】:

    【解决方案2】:

    问题不在于编辑注册链接,原因在于您的路线:

    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) %>
    

    或者,如果您希望配置文件仅作用于当前用户,请在 routes.rb 中将其设置为单一资源:

    resource :profile
    

    【讨论】:

      【解决方案3】:

      我有同样的问题。通过编辑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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-13
        • 1970-01-01
        • 1970-01-01
        • 2012-07-16
        相关资源
        最近更新 更多