feat(rails): support active storage attachments#283
Conversation
7 new issues
|
| add_attachment_fields(collection, options) | ||
| end | ||
|
|
||
| remove_active_storage_collections(datasource_customizer) if options.fetch(:hide_internal_collections, true) |
| end | ||
| end | ||
|
|
||
| def add_file_field(collection, model_class, attachment_name, download_images_on_list) |
| end | ||
| end | ||
|
|
||
| def compute_values(records, model_class, attachment_name, download_images_on_list) |
| else | ||
| "data:#{blob.content_type};name=#{CGI.escape(blob.filename.to_s)};base64," | ||
| end | ||
| end |
| end | ||
| end | ||
|
|
||
| def handle_write(value, context, model_class, attachment_name) |
| ) | ||
| end | ||
| end | ||
| {} |
|
|
||
| current = current.child_collection | ||
| end | ||
| nil |
| end | ||
|
|
||
| def handle_write(value, context, model_class, attachment_name) | ||
| record_id = context.filter&.condition_tree&.value |
There was a problem hiding this comment.
🟢 Low plugins/active_storage.rb:97
Line 97 calls context.filter&.condition_tree&.value, assuming condition_tree is always a leaf node with a value attribute. When the filter contains compound conditions (AND/OR), condition_tree is a branch node that doesn't respond to .value, so the code throws NoMethodError: undefined method 'value'. Consider checking that condition_tree responds to value before accessing it, or handle the compound case explicitly.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file packages/forest_admin_rails/lib/forest_admin_rails/plugins/active_storage.rb around line 97:
Line 97 calls `context.filter&.condition_tree&.value`, assuming `condition_tree` is always a leaf node with a `value` attribute. When the filter contains compound conditions (AND/OR), `condition_tree` is a branch node that doesn't respond to `.value`, so the code throws `NoMethodError: undefined method 'value'`. Consider checking that `condition_tree` responds to `value` before accessing it, or handle the compound case explicitly.
Evidence trail:
packages/forest_admin_rails/lib/forest_admin_rails/plugins/active_storage.rb line 97: `record_id = context.filter&.condition_tree&.value`
packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/components/query/condition_tree/nodes/condition_tree_leaf.rb line 13: `attr_reader :field, :operator, :value`
packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/components/query/condition_tree/nodes/condition_tree_branch.rb line 7: `attr_reader :aggregator, :conditions` (no `value` attribute)
packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/components/query/condition_tree/nodes/condition_tree.rb: base class does not define `value` method
Review of Macroscope's findingsLine 97 — Not an issue. Line 82 — Type mismatch between Most relevant point. Line 106 — Malformed data URI silently ignored in Not a concern. The data URI is built by the Forest Admin frontend, not user input. A malformed data URI means a frontend bug, not a user error. The current behavior (no-op) is acceptable — crashing would be equally valid but wouldn't improve the UX since the user can't fix a malformed data URI. No fix needed. |
# [1.27.0](v1.26.3...v1.27.0) (2026-04-01) ### Features * **rails:** support active storage attachments ([#283](#283)) ([7076b1b](7076b1b))
|
🎉 This PR is included in version 1.27.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
has_one_attachedfields as File fields in Forest AdminOptions
only/except— filter which collections the plugin processeshide_internal_collections— show/hide ActiveStorage internal collections (default: true)download_images_on_list— download images on list view for preview (default: false)Note
Add Active Storage attachment support to Forest Admin Rails agent
has_one_attachedfields and adds a computedFilecolumn per attachment returning a data URI (Base64 content on record views, optionally for images on list views).only,except,hide_internal_collections, anddownload_images_on_listoptions; internal Active Storage collections (Attachment,Blob,VariantRecord) are hidden by default.ForestAdmin::Types::ActiveStoragePluginvia a lazy autoload in types.rb.📊 Macroscope summarized 5512b24. 6 files reviewed, 11 issues evaluated, 2 issues filtered, 1 comment posted
🗂️ Filtered Issues
packages/forest_admin_rails/lib/forest_admin_rails/plugins/active_storage.rb — 1 comment posted, 11 evaluated, 2 filtered
compute_values. Line 79 uses.index_by(&:id)which creates hash keys using the model's native id type (typicallyInteger). Line 82 looks up withrecord['id']which may be aStringif records come from serialized data. Whenrecord['id']is"123"(String) butmodelskeys are123(Integer), the lookup returnsniland the attachment appears missing even when it exists. [ Failed validation ]handle_write, ifForestAdminAgent::Utils::Schema::ForestValueConverter.parse_data_uri(value)returnsnilfor a non-empty value (malformed data URI), the attachment is silently not updated. The user may expect an error or the old attachment to be purged, but neither happens - the old attachment remains and no feedback is provided. [ Failed validation ]