aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib/active_storage/attached
Commit message (Collapse)AuthorAgeFilesLines
* It may be better to explicitly require 'object/try' where we call `try`Akira Matsuda2019-08-011-0/+2
| | | | | | In most cases it works now without explicit require because it's accidentally required through active_support/core_ext/date_and_time/calculations.rb where we still call `try`, but that would stop working if we changed the Calculations implementation and remove the require call there.
* Preserve existing attachment assignment behavior for upgraded appsGeorge Claghorn2019-07-201-5/+12
| | | | | | | | | Assigning to a collection of attachments appends rather than replacing, as in 5.2. Existing 5.2 apps that rely on this behavior will no longer break when they're upgraded to 6.0. For apps generated on 6.0 or newer, assigning replaces the existing attachments in the collection. #attach should be used to add new attachments to the collection without removing existing ones. I expect that we'll deprecate the old behavior in 6.1. Closes #36374.
* Add :allow_nil option to delegate_missing_to; use in ActiveStorageMatt Tanous2019-05-231-1/+1
| | | | attachment
* [ActiveStorage] Ensure that the `_blob` association is properly loaded when ↵Abhishek Chandrasekhar2019-02-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | attaching `::One` Consider a model with `One` and `Many` attachments configured: class User < ActiveRecord::Base has_one_attached :avatar has_many_attached :highlights end === One Attachment After attaching `One` attachment (`:avatar`), we can see that the associated `_blob` record (`:avatar_blob`) still returns as `nil`. user.avatar.attach(blob) user.avatar_attachment.present? => true user.avatar_blob.present? => false # Incorrect! This is a false negative. It happens because after the attachment and blob are built: 1. The record already has its `_blob` association loaded, as `nil` 2. the `::Attachment` is associated with the record but the `::Blob` only gets associated with the `::Attachment`, not the record itself In reality, the blob does in fact exist. We can verify this as follows: user.avatar.attach(blob) user.avatar_attachment.blob.present? => true # Blob does exist! The fix in this change is to simply assign the `::Blob` when assigning the `::Attachment`. After this fix is applied, we correctly observe: user.avatar.attach(blob) user.avatar_attachment.present? => true user.avatar_blob.present? => true # Woohoo! === Many Attachments We don't see this issue with `Many` attachments because the `_blob` association is already loaded as part of attaching more/newer blobs. user.highlights.attach(blob) user.highlights_attachments.any? => true user.highlights_blobs.any? => true
* Remove unused attributeGeorge Claghorn2018-07-211-2/+2
|
* Fix replacing many attachments via assign and attachGeorge Claghorn2018-07-171-0/+4
|
* Fix that successive ActiveStorage::Attached::Many#attach calls would ↵George Claghorn2018-07-161-1/+11
| | | | overwrite previous attachments
* Clear attachment changes on reloadGeorge Claghorn2018-07-131-0/+4
|
* Implement ActiveStorage::Attached::{One,Many}#attach in terms of changesGeorge Claghorn2018-07-134-18/+30
|
* Fix that detaching could purgeGeorge Claghorn2018-07-132-2/+2
|
* Fix analyzing new blobs from uploaded files on attachGeorge Claghorn2018-07-131-18/+4
|
* Raise an ArgumentError instead of a RuntimeErrorGeorge Claghorn2018-07-081-1/+1
|
* Store newly-uploaded files on save rather than assignmentGeorge Claghorn2018-07-0710-136/+319
|
* Reflection for attachmentsKevin Deisz2018-05-301-0/+12
| | | | Add the ability to reflect on the attachments that have been defined using ActiveRecord::Reflection.
* Generate getter and setter methods in mixinJosh Susser2018-05-171-2/+2
| | | | | | | | | | | Generated attachment getter and setter methods are created within the model's `GeneratedAssociationMethods` module to allow overriding and composition using `super`. Includes tests for new functionality. Co-authored-by: Josh Susser <josh@hasmanythrough.com> Co-authored-by: Jamon Douglas <terrildouglas@gmail.com>
* Merge pull request #31956 from fatkodima/has_attached-presence-validationEileen M. Uchitelle2018-04-271-0/+4
|\ | | | | has_(one/many)_attached presence validation
| * has_(one/many)_attached presence validationfatkodima2018-02-111-0/+4
| |
* | Allow selectively purging attached blobsNicholas Shirley2018-03-062-12/+18
| |
* | Fix purging dependent blobs when attachments aren't loadedGeorge Claghorn2018-03-052-23/+17
| |
* | Delete dependent attachments with recordGeorge Claghorn2018-03-051-2/+2
| | | | | | | | [Matt Jones & George Claghorn]
* | Handle another case where a blob might be erroneously purgedGeorge Claghorn2018-03-041-5/+10
| |
* | Avoid purging attached blob when replacing it with itselfGeorge Claghorn2018-03-041-2/+6
|/
* Change Active Storage destroy callbackskami-zh2018-01-091-2/+2
| | | | | There is concern that only blob are deleted depending on the `before_destroy` definition order which throws abort.
* Fix attaching blobs to optimistically-locked recordsGeorge Claghorn2018-01-081-2/+2
| | | | | | Explicitly declare inverse associations so ActiveStorage::Attachment touches the original record instance. Closes #31542.
* Provide attachment writersGeorge Claghorn2017-11-201-0/+8
| | | | | | | | | | | | | Permit creating a record and attaching files in a single step. # Before: User.create!(user_params.except(:avatar)).tap do |user| user.avatar.attach(user_params[:avatar]) end # After: User.create!(user_params) [Yoshiyuki Hirano & George Claghorn]
* Permit attaching files to new recordsGeorge Claghorn2017-11-192-5/+9
| | | | Closes #31164.
* Introduce ActiveStorage::Attached::{One,Many}#detachGeorge Claghorn2017-11-142-7/+14
|
* Extract metadata from images and videosGeorge Claghorn2017-10-221-1/+5
|
* Add `with_attached_*` scope to `has_one_attached` macroYoshiyuki Hirano2017-09-191-0/+6
| | | | | * For avoiding N+1 problem, added `with_attached_*` scope to `has_one_attached` macro.
* Fix file missing in activestorage's example code [ci skip]Yoshiyuki Hirano2017-09-172-2/+2
| | | | | * File.open("~/face.jpg") raise error: `Errno::ENOENT: No such file or directory @ rb_sysopen - ~/face.jpg`
* RefactorGeorge Claghorn2017-08-291-12/+10
|
* Fix replacing a singular attachmentGeorge Claghorn2017-08-292-4/+22
|
* Update Active Storage docs [ci skip]Yoshiyuki Hirano2017-08-301-1/+1
|
* minor tweaks in Active Storage after a walkthroughXavier Noria2017-08-151-1/+1
|
* Use frozen string literal in Active StorageKoichi ITO2017-08-123-0/+6
|
* Merge pull request #30147 from yhirano55/fix_trailing_blank_linesRafael França2017-08-111-1/+0
|\ | | | | [Active Storage] `rubocop -a --only Layout/TrailingBlankLines`
| * [Active Storage] `rubocop -a --only Layout/TrailingBlankLines`Yoshiyuki Hirano2017-08-092-2/+1
| |
* | Evaluate `@active_storage_attached_#{name}` only onceRyuta Kamizono2017-08-121-12/+8
| | | | | | | | | | Currently `"@active_storage_attached_#{name}"` in `define_method` is evaluated every call. It is better to evaluate it only once.
* | Fix formatting of Active Storage docs [ci skip]yuuji.yaginuma2017-08-112-14/+14
|/ | | | | * Use `+` instead of backquote. * Remove escape from class to be link
* Merge branch 'master' into ast-moduleDavid Heinemeier Hansson2017-08-051-3/+9
|\
| * Fix ruby warningsyuuji.yaginuma2017-08-051-2/+8
| | | | | | | | | | | | | | | | | | | | This fixes following warnings: ``` test/models/variant_test.rb:11: warning: ambiguous first argument; put parentheses or a space even after `/' operator lib/active_storage/attached/macros.rb:63: warning: instance variable @active_storage_attached_highlights not initialized lib/active_storage/attached/macros.rb:25: warning: instance variable @active_storage_attached_avatar not initialized ```
* | `module ActiveStorage`, not `ActiveStorage::Class`claudiob2017-08-043-154/+161
|/ | | | | | | | | | | | | | | | | | The reasons for this commit are: - uniformity with the other Rails libraries - (possibly) behave better with respect to autoloading - fix the index in the generated documentation Before this commit, run `rake rdoc` generates this left sidebar (ActiveStorage entries are indexed twice, both inside and outside the module): <img width="308" alt="before" src="https://user-images.githubusercontent.com/10076/28939523-7c087dec-7846-11e7-9289-38ed4a2930cd.png"> After this commit, run `rake rdoc` generates this left sidebar: (ActiveStorage entries are only indexed inside the module): <img width="303" alt="after" src="https://user-images.githubusercontent.com/10076/28939524-7c090be0-7846-11e7-8ee5-29dfecae548e.png">
* Add 'activestorage/' from commit '3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58'Rafael Mendonça França2017-07-313-0/+183
git-subtree-dir: activestorage git-subtree-mainline: 0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6 git-subtree-split: 3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58