【问题标题】:Could not find devise mapping for path找不到路径的设计映射
【发布时间】:2017-08-10 13:22:27
【问题描述】:

我的 routes.rb 中定义了以下路由

devise_for :users, controllers: { registrations: "network/registrations",sessions: 'network/sessions', passwords: 'network/passwords' }


devise_scope :user do
   get "registrations/show" => "network/registrations", as: :show_user_profile
end

当我做 rake 路线时,我也看到了

 network_show_user_profile GET    /network/registrations/show(.:format)                                                                network/registrations#show

但是当我尝试访问路径 /network/registrations/show

我得到以下异常

找不到路径“/network/registrations/show”的设计映射。 这可能有两个原因:

1) You forgot to wrap your route inside the scope block. For example:

  devise_scope :user do
    get "/some/route" => "some_devise_controller"
  end

2) You are testing a Devise controller bypassing the router.
   If so, you can explicitly tell Devise which mapping to use:

   @request.env["devise.mapping"] = Devise.mappings[:user]

我尝试修改 routes.rb 并添加

devise_scope :user do
  get 'user_profile' => 'registrations#search', :as => 'user_profile'
end

当我访问 user_profile 路径时,我得到了错误

The action 'show' could not be found for Network::RegistrationsController

但是当我将动作显示添加到控制器时,我再次收到相同的异常消息

找不到路径“/network/registrations/show”的设计映射。 这可能有两个原因:

1) You forgot to wrap your route inside the scope block. For example:

  devise_scope :user do
    get "/some/route" => "some_devise_controller"
  end

2) You are testing a Devise controller bypassing the router.
   If so, you can explicitly tell Devise which mapping to use:

   @request.env["devise.mapping"] = Devise.mappings[:user]

任何关于我做错了什么的帮助将不胜感激。谢谢。

【问题讨论】:

    标签: ruby ruby-on-rails-4 devise


    【解决方案1】:

    我尝试添加与您相同的路线

    Rails.application.routes.draw do
    
      devise_for :users, controllers: { registrations: "network/registrations",sessions: 'network/sessions', passwords: 'network/passwords' }
    
    
      devise_scope :user do
         get "registrations/show" => "network/registrations", as: :show_user_profile
      end
    end
    

    但不是

    network_show_user_profile GET /network/registrations/show(.:format)

    我收到了show_user_profile GET /registrations/show(.:format) registrations#show

    所以我用下面替换了这个路由文件

    Rails.application.routes.draw do
    
      devise_for :users, controllers: { registrations: "network/registrations",sessions: 'network/sessions', passwords: 'network/passwords' }
    
    
      devise_scope :user do
         get "/network/registrations/show" => "network/registrations#show", as: :show_user_profile
      end
    end
    

    我还在network/registrations_controller.rb 中创建了一个动作show

    一切都适合我。

    希望这会有所帮助。

    【讨论】:

    • 嗨@nimish 再次为您的回复。但它仍然给我同样的错误,不知道我在做什么错误
    • 请分享您的 route.rb 并完成错误跟踪
    • 嗨 Nimish,我已经更新了这个问题。你能检查一下这是否有帮助吗?
    • Nimish 我创建了一个简单的 Rails 应用程序来调试它,一旦我使用命名空间进行路由,问题就会出现。
    • 你找到解决办法了吗?
    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多