Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omit action mailbox, activestorage, and conductor routes from bin/rails routes in Rails 6?

I have a brand new Rails 6 app and without anything in the config/routes.rb, the output of bin/rails routes has a massive list of very long urls for ActiveStorage, Action Mailbox, and conductor.

This is making bin/rails routes completely useless as a form of documentation, especially since the options for bin/rails routes don't allow filtering out things.

I don't want to omit these parts of Rails as I may need them. But I would prefer these routes a) not exist if I'm not using them and b) not show up in bin/rails routes.

Does anyone know how to make this work?

like image 398
davetron5000 Avatar asked Jan 04 '20 18:01

davetron5000


2 Answers

You can have the ActionMailbox routes omitted by commenting out the specific require line in your application.rb.

Specifically if you comment the require "action_mailbox/engine" line you'll no longer see any of the /rails/action_mailbox or /rails/conductor/action_mailbox routes.

You'll need to restart the app for the changes to take affect.

like image 194
Arian Amador Avatar answered Nov 13 '22 01:11

Arian Amador


As of Rails 6.0.2.1, this is the way to do it:

In config/application.rb, remove the line require "rails/all" and replace it with this:

# See https://github.com/rails/rails/blob/v6.0.2.1/railties/lib/rails/all.rb for the list
# of what is being included here
require "rails"

# This list is here as documentation only - it's not used
omitted = %w(
  active_storage/engine
  action_cable/engine
  action_mailbox/engine
  action_text/engine
)

# Only the frameworks in Rails that do not pollute our routes
%w(
  active_record/railtie
  action_controller/railtie
  action_view/railtie
  action_mailer/railtie
  active_job/railtie
  rails/test_unit/railtie
  sprockets/railtie
).each do |railtie|
  begin
    require railtie
  rescue LoadError
  end
end

Note that if you leave actiontext in, you still get a few active storage routes included. Not sure why. This configuration basically means you cannot use active storage, action text, or action mailbox. Bringing those back in will bring back many routes you will never need.

Also note this solution has a carrying cost because with each Rails version upgrade, you must examine rails/all.rb to make sure no new frameworks were added that you might care about (or removed that you no longer should be requiring).

like image 14
davetron5000 Avatar answered Nov 13 '22 03:11

davetron5000