aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/models/active_storage/blob.rb
diff options
context:
space:
mode:
authorEugene Kenny <elkenny@gmail.com>2018-02-14 23:15:12 +0000
committerEugene Kenny <elkenny@gmail.com>2018-02-14 23:15:12 +0000
commit1e55ee5a283df448c6cf4c4d3bb9c98e49927520 (patch)
tree417026cddcb1d80c1b5c0f95c6665eed0451bc3f /activestorage/app/models/active_storage/blob.rb
parentfa9e791e014a650f5ea6a14b283fed9621fc83e2 (diff)
downloadrails-1e55ee5a283df448c6cf4c4d3bb9c98e49927520.tar.gz
rails-1e55ee5a283df448c6cf4c4d3bb9c98e49927520.tar.bz2
rails-1e55ee5a283df448c6cf4c4d3bb9c98e49927520.zip
Use require_dependency inside Active Storage
Active Storage is an engine which means its models, jobs and controllers are autoloaded by Rails rather than Ruby. Unfortunately this means it's subject to the same gotchas as applications, including this one: http://guides.rubyonrails.org/v5.1.4/autoloading_and_reloading_constants.html#when-constants-aren-t-missed-qualified-references On Ruby < 2.5, constants nested under classes can't be autoloaded by Rails if a top level constant already exists with the same name. To avoid clashing with constants defined in users' applications or gems, we can use `require_dependency` to ensure that the nested constants are loaded before they're used.
Diffstat (limited to 'activestorage/app/models/active_storage/blob.rb')
-rw-r--r--activestorage/app/models/active_storage/blob.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb
index 3bcd7599d0..31fbc66965 100644
--- a/activestorage/app/models/active_storage/blob.rb
+++ b/activestorage/app/models/active_storage/blob.rb
@@ -14,9 +14,13 @@
# update a blob's metadata on a subsequent pass, but you should not update the key or change the uploaded file.
# If you need to create a derivative or otherwise change the blob, simply create a new blob and purge the old one.
class ActiveStorage::Blob < ActiveRecord::Base
- include ActiveStorage::Blob::Analyzable
- include ActiveStorage::Blob::Identifiable
- include ActiveStorage::Blob::Representable
+ require_dependency "active_storage/blob/analyzable"
+ require_dependency "active_storage/blob/identifiable"
+ require_dependency "active_storage/blob/representable"
+
+ include Analyzable
+ include Identifiable
+ include Representable
self.table_name = "active_storage_blobs"