【问题标题】:Devise in namespace - ActionController::RoutingError (No route matches {:action=>"new", :controller=>"devise/sessions"})在命名空间中设计 - ActionController::RoutingError (没有路由匹配 {:action=>"new", :controller=>"devise/sessions"})
【发布时间】:2010-12-09 23:33:19
【问题描述】:

我正在使用 Devise,一切运行良好,但我现在正尝试将内容移至“管理员”命名空间。

我有一条看起来像这样的路线:

namespace :admin do
  devise_for :users, :controllers => { :registrations => "admin/users/registrations" }
end

在我的一个控制器中,我有

before_filter :authenticate_user!

但是当它被调用时,它会抛出:

ActionController::RoutingError (No route matches {:action=>"new", :controller=>"devise/sessions"}): 

有什么想法吗?

【问题讨论】:

  • 您的 RegistrationsController 是什么样的?

标签: ruby-on-rails devise


【解决方案1】:

根据设计文档(自此发布以来可能已更改),您可以使用以下说明:

#    ...
#    
#    Notice that whenever you use namespace in the router DSL, it automatically sets the module.
#    So the following setup:
#
#      namespace :publisher do
#        devise_for :account
#      end
#
#    Will use publisher/sessions controller instead of devise/sessions controller. You can revert
#    this by providing the :module option to devise_for.
#    
#    ...

希望这对某人有所帮助。

【讨论】:

    【解决方案2】:

    我正在这样做:

    scope '/admin' do
      devise_for :admins
    end
    

    【讨论】:

      【解决方案3】:

      解决方法是使用path 选项并将devise_for 移出 namespace 块:

      devise_for :users, :path => '/admin',
                         :controllers => { :registrations => "admin/users/registrations" }
      namespace :admin do
        # other resource controllers
      end
      

      也许它没有那么优雅(或直观),但它对我有用!

      【讨论】:

        猜你喜欢
        • 2018-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 2016-08-25
        • 2018-11-21
        相关资源
        最近更新 更多