Fix: NoMethodError (MAYBE-RAILS-CV) #1659
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The error occurs because we're trying to call
delete_all
onActiveStorage::Variant
, which is a processing utility class, rather thanActiveStorage::VariantRecord
, which is the ActiveRecord model that actually corresponds to the database tableactive_storage_variant_records
.From examining the schema.rb file, we can see that Active Storage is properly set up with the
active_storage_variant_records
table (line 142-146). The original code was attempting to perform bulk deletion using the wrong class.To fix this, we need to replace any calls to
ActiveStorage::Variant.delete_all
withActiveStorage::VariantRecord.delete_all
. TheVariantRecord
class is the proper ActiveRecord model that has access to thedelete_all
class method through its inheritance fromApplicationRecord
.Based on the existing test conventions shown in test/models/user_test.rb, I'm adding a new test file specifically for testing Active Storage variant record management. The test follows the established patterns of:
The test will verify that:
Tip
You can make revisions or ask questions of Revise.dev by using
/revise
in any comment or review!/revise Add a comment above the method to explain why we're making this change.
/revise Why did you choose to make this change specifically?
Important
If something doesn't look right, click to retry this interaction.