Ruby-on-rails – Using devise scope to redefine default routes

deviseruby-on-rails

Geting an error when trying to redefine the session routes using devise scopes.

devise_for :users
devise_scope :users do
  get    '/login'   => 'devise/sessions#new',     as: :new_user_session
  post   '/login'   => 'devise/sessions#create',  as: :user_session
  delete '/logout'  => 'devise/sessions#destroy', as: :destroy_user_session
end

The error.

Invalid route name, already in use: 'new_user_session' You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes

I understand the error just not why its happening. wouldn't the scope redefine the as new_user_session?

Also if you follow the wiki you will get a devise deprecation warning for passing a block.
https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

Best Answer

Guess I needed to skip the sessions devise_for :users, :skip => [:sessions]

Related Topic