annotate_models
annotate_models copied to clipboard
Annotate routes shows unwanted info in Rails 6
When I annotate just the routes, I want to see all the routes that I created. However annotate also shows other routes like rails_postmark_inbound_emails, rails_direct_uploads which are related to Action Mailbox and Active Storage which I do not wish to see. Is there a way to suppress showing these routes in annotate?
Commands
$ annotate --routes
Version
- annotate 3.1.1
- Rails 6.0.3.4
- ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
@overdrivemachines If you're not using ActionMailbox nor ActiveStorage you can disable their routes using this method: https://stackoverflow.com/a/58041853/9375533
@overdrivemachines If you're not using ActionMailbox nor ActiveStorage you can disable their routes using this method: https://stackoverflow.com/a/58041853/9375533
If we do that, Active Storage and Action Mailbox will be disabled too, won't they?
@overdrivemachines
I think it just removes the routes, if you want to disable them completely you need to unrequire them.
Instead of:
require 'rails/all'
You can do:
require 'active_record/railtie'
# require 'active_storage/engine'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'action_mailer/railtie'
require 'active_job/railtie'
require 'action_cable/engine'
# require 'action_mailbox/engine'
require 'action_text/engine'
require 'rails/test_unit/railtie'
require 'sprockets/railtie'
@dcangulo Im not trying to remove the routes or disable any features. All I want is annotate --routes to not show those routes. Perhaps a new feature can be added to hide routes for Active Storage and Action Mailbox
@overdrivemachines Oh, I see. We just have a different use case where I don't use both ActiveStorage and ActionMailbox so I can just safely remove their route for it not to appear in generated route comments.
I came up with a solution. Create lib/tasks/routes.rake:
task routes: :environment do
Rails.application.eager_load!
models = ApplicationRecord.descendants.collect(&:name).join("|").downcase
controllers = ApplicationController.descendants.collect(&:name)
controllers = (controllers.map { |controller| controller[0..-11].downcase }).join("|")
if models
puts `bundle exec rails routes -g "#{models}|#{controllers}"`
else
puts `bundle exec rails routes -g "#{controllers}"`
end
end
This only shows models and controllers created by the user