devise icon indicating copy to clipboard operation
devise copied to clipboard

Devise ignores active storage draw_routes config for routes generation.

Open phlegx opened this issue 4 years ago • 5 comments

Environment

  • Ruby 2.7.2
  • Rails 6.1.4
  • Devise 4.8.0

Current behavior

  1. Add devise to Gemfile.
  2. Add config.active_storage.draw_routes = false to config/application.rb.
  3. Draw own active storage routes with example naming as: rails_service_blob.
  4. Start server RAILS_ENV=staging rails s. No error on development environment!
  5. Crash and error...
/home/user/.rvm/gems/ruby-2.7.2@app/gems/actionpack-6.1.4/lib/action_dispatch/routing/route_set.rb:587:in `add_route': Invalid route name, already in use: 'rails_service_blob'
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:
https://guides.rubyonrails.org/routing.html#restricting-the-routes-created (ArgumentError)
...
from /home/user/.rvm/gems/ruby-2.7.2@app/gems/railties-6.1.4/lib/rails/application.rb:169:in `reload_routes!'
from /home/user/.rvm/gems/ruby-2.7.2@app/gems/devise-4.8.0/lib/devise/rails.rb:17:in `block in <class:Engine>'
...

Expected behavior

Run Rails server as expected. On development environment all works fine. Without Devise installed, server starts fine on all environments.

Found out that config.eager_load = true in staging and production environment is the difference to development. Setting eager load to false on staging and production starts the server without crash. But it should work also with eager load set to true.

See: https://github.com/heartcombo/devise/blob/5d5636f03ac19e8188d99c044d4b5e90124313af/lib/devise/rails.rb#L17

Setting Devise with config.reload_routes = false prevents server crash. But what are the side effects setting this config to false?

phlegx avatar Aug 27 '21 09:08 phlegx

Found a workaround, add this to application.rb:

config.before_configuration do |app|
  ActiveStorage.draw_routes = false
end

kshnurov avatar Aug 14 '22 18:08 kshnurov

Confirmed this is still an issue on Rails 7.1.0.alpha. The config.before_configuration didn't work for me, but config.reload_routes = false in the Devise initializer did solve it. I'm not sure about the conditions where having that enabled would be important, but it seems like an odd default. Also weird that on app.reload_routes! that the ActiveStorage setting for draw_routes is ignored. That suggests this might be a Rails bug...

rgarver avatar Mar 03 '23 00:03 rgarver