#5400·devise

Devise ignores active storage draw_routes config for routes generation.

Author: phlegxCreated Aug 27, 2021Updated Aug 5, 2026

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?