我目前在我的rails应用程序中使用Devise.我想用我的api添加Devise Token Auth进行身份验证.当我尝试使用设置devise_token_auth时
rails g devise_token_auth:install User auth rake db:migrate
我收到以下错误:
~/workspace (devise_token_auth) $ rake db:migrate --trace ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! ArgumentError: 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 created with `resources` as explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:557:in `add_route' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1561:in `add_route' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1536:in `decomposed_match' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1534:in `block in decomposed_match' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1419:in `block (2 levels) in member' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:816:in `scope' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1419:in `block in member' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1665:in `with_scope_level' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1415:in `member' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1534:in `decomposed_match' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1517:in `block in match' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1507:in `each' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1507:in `match' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:689:in `map_method' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:650:in `get' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:374:in `block in devise_session' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1198:in `block in resource' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1676:in `block (2 levels) in resource_scope' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:816:in `scope' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1676:in `block in resource_scope' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1665:in `with_scope_level' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1675:in `resource_scope' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1197:in `resource' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:373:in `devise_session' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:263:in `block (4 levels) in devise_for' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:263:in `each' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:263:in `block (3 levels) in devise_for' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:461:in `with_devise_exclusive_scope' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:262:in `block (2 levels) in devise_for' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:365:in `block in devise_scope' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:940:in `block in constraints' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:816:in `scope' /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:940:in `constraints' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:364:in `devise_scope' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:261:in `block in devise_for' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:237:in `each' /usr/local/rvm/gems/ruby-2.2.1/gems/devise-3.5.3/lib/devise/rails/routes.rb:237:in `devise_for' /home/ubuntu/workspace/config/routes.rb:3:in `block in我理解这是因为路线上的冲突.我如何让它工作?有什么办法吗?
1> Sourabh..:为了使用devise_token_auth和devise,我们需要在devise_token_auth初始化程序中设置一个标志,如下所示:
DeviseTokenAuth.setup do |config| # enable_standard_devise_support = false end和路由文件也需要更改
Rails.application.routes.draw do # standard devise routes available at /users # NOTE: make sure this comes first!!! devise_for :users # token auth routes available at /api/v1/auth namespace :api do scope :v1 do mount_devise_token_auth_for 'User', at: 'auth' end end end我在Devise Token Auth FAQs中找到了这个