36

Upgrading Rails to 5.2, and I found out that I must commit the storage.yml into version control. I don't plan to use ActiveStorage. Is there a way to disable it?

lulalala
  • 17,572
  • 15
  • 110
  • 169

4 Answers4

44

Remove next line from config/application.rb

require "active_storage/engine"

Remove next line from environments config/environments/*.rb

config.active_storage.service = :local

Remove next line from app/assets/javascripts/application.js

//= require activestorage

ActiveStorage rails routes will vanish

In case there is statement require 'rails/all' in application.rb then you can use solution provided below where you need to require dependency by dependency and to omit active_storage.

borisaeric
  • 573
  • 5
  • 12
  • I've done this but running rake routes still yields the `/rails/active_storage...` routes – Flov Oct 20 '18 at 14:52
  • 1
    Now it's little bit different because in `application.rb` there is statement `require 'rails/all'` so you need to require dependency by dependency and make sure not to omit something important. See answer below for reference. – borisaeric Oct 27 '18 at 18:30
  • I've just tested it, below solution works for this case when there is `require 'rails/all'` – borisaeric Oct 27 '18 at 18:44
24

The only solution I've found so far is in config/application.rb, replacing:

require 'rails/all'

With:

require "rails"

# Include each railties manually, excluding `active_storage/engine`
%w(
  active_record/railtie
  action_controller/railtie
  action_view/railtie
  action_mailer/railtie
  active_job/railtie
  action_cable/engine
  rails/test_unit/railtie
  sprockets/railtie
).each do |railtie|
  begin
    require railtie
  rescue LoadError
  end
end

which is taken from Rails' source.

Jan Klimo
  • 4,643
  • 2
  • 36
  • 42
MikeRogers0
  • 721
  • 6
  • 14
3

Remove lines like the following from config/environments/*.rb

config.active_storage.service = :local

Rails will then not load the yaml file.

lulalala
  • 17,572
  • 15
  • 110
  • 169
  • 1
    Will this completely stop the engine to be loaded at app boot? Isn't there something like `config.active_storage = false` ? – coding addicted Apr 13 '18 at 11:00
  • @codingaddicted I didn't see that in the document. Well my main issue is that it tries to load a YAML file which I don't want/need. – lulalala Apr 14 '18 at 01:47
  • yes the docs aren't quite complete I believe. Lot's of my questions stay without response about active storage for now :( – coding addicted Apr 14 '18 at 10:59
  • @codingaddicted if your solution works? Post it as an answer so I can accept it. – lulalala Apr 14 '18 at 12:30
  • 1
    I didn't find a solution yet, I think @MikeRogers0 approach can worth a try. I don't understand why you got a negative rating on yours as it is a valid alternative too. up for the balance ;) – coding addicted Apr 14 '18 at 12:59
0

I ran into this migrating from Rails 5 to 6. I'm also not using active storage, had removed all references to it, and had tried the answer above overriding the require rails/all idea, yet still ran into this error.

It was actually simpler to commit an empty config/storage.yml into source. This doesn't mean you need to start using ActiveStorage anywhere in your app (to OP's original point), and will give you a more standard rails configuration, rather than worry about diverging from what require rails/all does in future updates.

For completeness, here's the boilerplate config/storage.yml you can add to address this issue.

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
#   service: S3
#   access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
#   secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
#   region: us-east-1
#   bucket: your_own_bucket

# Remember not to checkin your GCS keyfile to a repository
# google:
#   service: GCS
#   project: your_project
#   credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
#   bucket: your_own_bucket

# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
#   service: AzureStorage
#   storage_account_name: your_account_name
#   storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
#   container: your_container_name

# mirror:
#   service: Mirror
#   primary: local
#   mirrors: [ amazon, google, microsoft ]
Kelton Temby
  • 825
  • 10
  • 20