[英]Devise in namespace - ActionController::RoutingError (No route matches {:action=>“new”, :controller=>“devise/sessions”})
I'm using Devise and everything has been working great, but I am now trying to move things into an 'admin' namespace. 我正在使用Devise,一切都很好,但我现在正试图将事情转移到'admin'命名空间。
I have a route that looks like: 我的路线看起来像:
namespace :admin do
devise_for :users, :controllers => { :registrations => "admin/users/registrations" }
end
In one of my controllers I have 在我的一个控制器中
before_filter :authenticate_user!
but when that gets called it throws: 但当它被调用时会抛出:
ActionController::RoutingError (No route matches {:action=>"new", :controller=>"devise/sessions"}):
Any ideas? 有任何想法吗?
As per the Devise documentation (which likely has changed since this posting), you could use the following instructions: 根据Devise文档(自发布以来可能已更改),您可以使用以下说明:
# ...
#
# 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.
#
# ...
Hope this helps someone. 希望这有助于某人。
I'm doing this: 我这样做:
scope '/admin' do
devise_for :admins
end
A workaround for this is to use the path
option and move devise_for
outside of the namespace
block: 解决方法是使用path
选项并在namespace
块之外移动devise_for
:
devise_for :users, :path => '/admin',
:controllers => { :registrations => "admin/users/registrations" }
namespace :admin do
# other resource controllers
end
Perhaps it's not as elegant (or intuitive), but it works for me! 也许它不那么优雅(或直观),但它对我有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.