I removed ActionStorage from config/application.rb
yet I see these routes when I run rake routes | less
.
I have nothing set up on my /config/routes.rb
...
Prefix Verb URI Pattern Controller#Action
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
Anyone know how I can remove these?
Two changes are needed to remove the ActiveStorage routes from an existing Rails app:
First, in config/application.rb
, comment out active_storage/engine
and action_text/engine
:
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "action_text/engine"
require "action_cable/engine"
require "rails/test_unit/railtie"
Then, in each environment
config file (e.g. config/development.rb
), comment out config.active_storage.service
:
# Store uploaded files on the local file system (see config/storage.yml for options).
# config.active_storage.service = :local
This will remove the ActiveStorage routes:
$ rails routes
You don't have any routes defined!
Please add some routes in config/routes.rb.
For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html.
Set the draw_routes
config to false on your application.rb config file https://github.com/rails/rails/blob/439d4995c1dab475b576fcb19ea95ae37e0ed222/guides/source/configuring.md#configuring-active-storage
config.active_storage.draw_routes = false
EDIT: as of now, the current stable release (6.0-stable) does not support this option, it's on the master branch and should work on the next release
There is an "official" way to do this, which is built-in into Rails. If you create new project with
$ rails new dummy_project --skip-active-storage
you can find in the newly created config/application.rb
exactly what you need (Rails 6.0.1 but works since 5.2):
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"
Replace require 'rails/all'
with the above snippet and you should be good to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With