huacnlee / rucaptcha

Captcha Gem for Rails, which generates captcha image by Rust.
https://huacnlee.github.io/rucaptcha
MIT License
695 stars 133 forks source link

Invalid route name, already in use: 'ru_captcha' (ArgumentError) #42

Closed netqyq closed 7 years ago

netqyq commented 7 years ago

部署使用生产环境,启动报错。在本地测试环境使用正常。不知是哪里有问题

routes.rb

  # rucaptcha
  mount RuCaptcha::Engine => "/rucaptcha"
Exiting
/usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:507:in `add_route': Invalid route name, already in use: 'ru_captcha'  (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 /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1657:in `add_route'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1628:in `decomposed_match'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1927:in `block in map_match'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1910:in `each'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1910:in `map_match'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1599:in `match'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:617:in `mount'
    from /data/ruby-apps/siziwang_travel/config/routes.rb:28:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:389:in `instance_exec'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:389:in `eval_block'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:371:in `draw'
    from /data/ruby-apps/siziwang_travel/config/routes.rb:1:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `block in load'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/file_update_checker.rb:77:in `execute'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/finisher.rb:119:in `block in <module:Finisher>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `run'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
    from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application.rb:352:in `initialize!'
    from /data/ruby-apps/siziwang_travel/config/environment.rb:5:in `<top (required)>'
    from /data/ruby-apps/siziwang_travel/config.ru:3:in `require_relative'
    from /data/ruby-apps/siziwang_travel/config.ru:3:in `block in <main>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
    from /data/ruby-apps/siziwang_travel/config.ru:in `new'
    from /data/ruby-apps/siziwang_travel/config.ru:in `<main>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:218:in `app'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/server.rb:59:in `app'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/server.rb:124:in `log_to_stdout'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/server.rb:77:in `start'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:90:in `block in server'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
    from /data/ruby-apps/siziwang_travel/bin/rails:9:in `require'
    from /data/ruby-apps/siziwang_travel/bin/rails:9:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
    from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
    from /data/ruby-apps/siziwang_travel/bin/spring:14:in `require'
    from /data/ruby-apps/siziwang_travel/bin/spring:14:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'
huacnlee commented 7 years ago

routes.rb

里面去掉 mount 这句,因为 RuCaptcha 内部已经实现挂载了

huacnlee commented 7 years ago

https://github.com/huacnlee/rucaptcha/blob/master/CHANGELOG.md#210

netqyq commented 7 years ago

升级到新版后,去掉这句句解决了。多谢! 免去了路由配置,进一步提升了用户体验!