使用devise和devise_token_Auth的路由不起作用

时间:2016-04-05 21:08:05

标签: ruby-on-rails ruby-on-rails-4 devise rails-routing rails-api

我没有使用Rails API gem,但我正在尝试在Rails中构建api。我正在使用设计宝石和devise_token_auth gem。我只是跑了一行:

rails g devise_token_auth:install FacilityUser auth

生成命令adbove工作但现在我的服务器不会启动。问题在于我的routes.rb文件。

Rails.application.routes.draw do

  devise_for :facility_users, ActiveAdmin::Devise.config

  devise_for :users, controllers: {registrations: "users/registrations", sessions: "users/sessions", passwords: "users/passwords"}, skip: [:sessions, :registrations]

  root 'landings#index'
  mount_devise_token_auth_for 'FacilityUser', at: 'auth'

end

当我的路由文件如上所述,当我尝试启动服务器时,我的日志中出现以下错误:

davids-MacBook-Pro:waynefacility davidmurray$ rails s
=> Booting WEBrick
=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:430:in `add_route': Invalid route name, already in use: 'new_facility_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
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1489:in `add_route'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1466:in `decomposed_match'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1464:in `block in decomposed_match'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1362:in `block (2 levels) in member'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:757:in `scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1362:in `block in member'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1594:in `with_scope_level'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1358:in `member'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1464:in `decomposed_match'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1447:in `block in match'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1437:in `each'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1437:in `match'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:630:in `map_method'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:591:in `get'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:377:in `block in devise_session'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1141:in `block in resource'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1605:in `block (2 levels) in resource_scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:757:in `scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1605:in `block in resource_scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1594:in `with_scope_level'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1604:in `resource_scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:1140:in `resource'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:376:in `devise_session'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:266:in `block (4 levels) in devise_for'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:266:in `each'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:266:in `block (3 levels) in devise_for'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:470:in `with_devise_exclusive_scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:265:in `block (2 levels) in devise_for'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:368:in `block in devise_scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:881:in `block in constraints'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:757:in `scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:881:in `constraints'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:367:in `devise_scope'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:264:in `block in devise_for'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:240:in `each'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/bundler/gems/devise-69bee06ceee6/lib/devise/rails/routes.rb:240:in `devise_for'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/devise_token_auth-0.1.37/lib/devise_token_auth/rails/routes.rb:25:in `mount_devise_token_auth_for'
    from /Users/davidmurray/projects/waynefacility/config/routes.rb:14:in `block in <top (required)>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:315:in `draw'
    from /Users/davidmurray/projects/waynefacility/config/routes.rb:1:in `<top (required)>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `call'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `execute'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `call'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
    from /Users/davidmurray/projects/waynefacility/config/environment.rb:5:in `<top (required)>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /Users/davidmurray/projects/waynefacility/config.ru:3:in `block in <main>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize'
    from /Users/davidmurray/projects/waynefacility/config.ru:in `new'
    from /Users/davidmurray/projects/waynefacility/config.ru:in `<main>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:49:in `eval'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:40:in `parse_file'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/server.rb:199:in `app'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/server.rb:50:in `app'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/server.rb:314:in `wrapped_app'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/server.rb:130:in `log_to_stdout'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/server.rb:67:in `start'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:81:in `block in server'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

如果我更改路由的顺序以便mount_devise_token_auth_for 'FacilityUser', at: 'auth'是第一行,那么我会收到以下错误:

davids-MacBook-Pro:waynefacility davidmurray$ rails s
=> Booting WEBrick
=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/devise_token_auth-0.1.37/lib/devise_token_auth/rails/routes.rb:40:in `block in mount_devise_token_auth_for': uninitialized constant ActionDispatch::Routing::Mapper::Scope (NameError)
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/devise_token_auth-0.1.37/lib/devise_token_auth/rails/routes.rb:86:in `unnest_namespace'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/devise_token_auth-0.1.37/lib/devise_token_auth/rails/routes.rb:32:in `mount_devise_token_auth_for'
    from /Users/davidmurray/projects/waynefacility/config/routes.rb:2:in `block in <top (required)>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:315:in `draw'
    from /Users/davidmurray/projects/waynefacility/config/routes.rb:1:in `<top (required)>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `call'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `execute'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `call'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
    from /Users/davidmurray/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
    from /Users/davidmurray/projects/waynefacility/config/environment.rb:5:in `<top (required)>'
    from /Users/davidmurray/projects/waynefacility/config.ru:3:in `block in <main>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize'
    from /Users/davidmurray/projects/waynefacility/config.ru:in `new'
    from /Users/davidmurray/projects/waynefacility/config.ru:in `<main>'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:49:in `eval'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:40:in `parse_file'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/server.rb:199:in `app'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/server.rb:50:in `app'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/rack-1.5.5/lib/rack/server.rb:314:in `wrapped_app'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/server.rb:130:in `log_to_stdout'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/server.rb:67:in `start'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:81:in `block in server'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/davidmurray/.rvm/gems/ruby-2.2.0/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我试着评论出一堆路线,所以我只有:

mount_devise_token_auth_for 'FacilityUser', at: 'auth'
root 'landings#index'

然后我仍然得到相同的block in mount_devise_token_auth_for': uninitialized constant ActionDispatch::Routing::Mapper::Scope (NameError)错误。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

我是这样用过的。它对我有用。

  # token auth routes available at /api/v1/auth
  namespace :api do
    scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth'
    end
  end

  # devise_for :users
  devise_for :users, controllers: {
    sessions:      'users/sessions',
    registrations: 'users/registrations'  
  }

答案 1 :(得分:0)

当您使用devise_token_auth时,您应该按照以下方式安装路线:

    Rails.application.routes.draw do
      # This one conflicts with mount_devise_token_auth,
      # if you want to use devise_token_auth you should only use
      # mount_devise_token_auth_for.
      # devise_for :facility_users, ActiveAdmin::Devise.config

      devise_for :users, controllers: { registrations: "users/registrations",
      sessions: "users/sessions",
      passwords: "users/passwords" },
      skip: [:sessions, :registrations]

      root 'landings#index'
      mount_devise_token_auth_for 'FacilityUser', at: 'auth'

    end

它应该有用。