diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-09 18:48:26 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2017-07-23 21:17:17 +0200 |
commit | 5963766d840ddcdb577a1bd10eb1491a4ef9132f (patch) | |
tree | e6cba96cac8865435486ba08a1a5fc0f04d6e9f7 /lib/active_storage/attached/one.rb | |
parent | 4efbeaeaab72be070e203f39726b37703c1db1fa (diff) | |
download | rails-5963766d840ddcdb577a1bd10eb1491a4ef9132f.tar.gz rails-5963766d840ddcdb577a1bd10eb1491a4ef9132f.tar.bz2 rails-5963766d840ddcdb577a1bd10eb1491a4ef9132f.zip |
Explore regular polymorphic associations rather than record_gid
Diffstat (limited to 'lib/active_storage/attached/one.rb')
-rw-r--r-- | lib/active_storage/attached/one.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/active_storage/attached/one.rb b/lib/active_storage/attached/one.rb index 80e4cb6234..02fc9c9abc 100644 --- a/lib/active_storage/attached/one.rb +++ b/lib/active_storage/attached/one.rb @@ -7,13 +7,13 @@ class ActiveStorage::Attached::One < ActiveStorage::Attached # You don't have to call this method to access the attachment's methods as # they are all available at the model level. def attachment - @attachment ||= ActiveStorage::Attachment.find_by(record_gid: record.to_gid.to_s, name: name) + @attachment ||= record.public_send("#{name}_attachment") end # Associates a given attachment with the current record, saving it to the # database. def attach(attachable) - @attachment = ActiveStorage::Attachment.create!(record_gid: record.to_gid.to_s, name: name, blob: create_blob_from(attachable)) + @attachment = ActiveStorage::Attachment.create!(record: record, name: name, blob: create_blob_from(attachable)) end # Checks the presence of the attachment. |