"devise / sessions"}) ...">

Develop in the namespace - ActionController :: RoutingError (There are no routes matching {: action => "new" ,: controller => "devise / sessions"})

I use Devise and everything works fine, but now I am trying to move things to the "admin" namespace.

I have a route that looks like this:

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 it is caused, he throws:

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

Any ideas?

+3
source share
3 answers

According to the developer documentation (which has probably changed since publication), you can use the following instructions:

#    ...
#    
#    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.

+3
source

I'm doing it:

scope '/admin' do
  devise_for :admins
end
+1

A workaround for this is to use the option pathand move devise_for outside the block namespace:

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

It may not be so elegant (or intuitive), but it works for me!

0
source

Source: https://habr.com/ru/post/1779504/


All Articles