Rails 4 + Devise: Invalid route name, already in u

2020-02-09 06:52发布

问题:

I'm following this how-to to modify the confirmation page after a successful sign up.

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration)

I do everything like it says but i get this error:

in `add_route': Invalid route name, already in use: 'new_user_session'  (ArgumentError)
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 created with `resources` as explained here: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

I guess the wiki is not updated for using Devise with Rails 4, but i don't find around enough information to fix the error.

The line which is returning the error is next (routes.rb):

devise_for :users, :controllers => { :registrations => "registrations" }

Any suggestion?

Thanks.

EDIT --

registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController

    protected

    def after_inactive_sign_up_path_for(resource)
        '/sign_up/inactive'
    end
end

routes.rb

root :to => 'home#index'
devise_for :users
resources :users

devise_for :users, :controllers => { :registrations => "registrations" }

回答1:

You have two routes devise_for :users in your routes.rb - remove the first one.