Skip to content

Commit

Permalink
add warning for active storage attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Jul 4, 2023
1 parent c8c66b8 commit e9bfcbc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docs/2.0/recipes/use-active-storage-attachments-as-associations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

[Active Storage](https://edgeguides.rubyonrails.org/active_storage_overview.html) is implemented as an association we can take advantage of that and make the users' experience so much better!

## `has_many`
## Create the resource

For that you should create an `attachment_resource.rb` and configure it like so.

```bash
bin/rails generate avo:resource active_record_attachment
```

:::warning
Please don't use the name `AttachmentResource` because the generated controller will override Avo's internal controller that handles the attachments.
:::

```ruby
class AttachmentResource < Avo::BaseResource
class ActiveRecordAttachmentResource < Avo::BaseResource
self.title = :filename
self.model_class = "ActiveStorage::Attachment"

Expand All @@ -18,6 +26,8 @@ class AttachmentResource < Avo::BaseResource
end
```

## `has_many`

Next, add it to your resource that `has_many_attached`:

```ruby
Expand Down

0 comments on commit e9bfcbc

Please sign in to comment.