Skip to content

Commit

Permalink
chore: add the attachment resource as a demo (#1829)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Jul 4, 2023
1 parent 092fb4a commit 765fc62
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/dummy/app/avo/resources/attachment_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AttachmentResource < Avo::BaseResource
self.title = :filename
self.model_class = "ActiveStorage::Attachment"

field :id, as: :id
field :filename, as: :text
field :service_url, as: :external_image, name: "Image"
field :created_at, as: :date_time
end
2 changes: 2 additions & 0 deletions spec/dummy/app/avo/resources/post_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class PostResource < Avo::BaseResource
extract_excerpt model.body
end

field :cover_photo_attachment, as: :has_one

field :is_featured, as: :boolean, visible: ->(resource:) { context[:user].is_admin? }
field :is_published, as: :boolean do |model|
model.published_at.present?
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/app/avo/resources/project_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ProjectResource < Avo::BaseResource
field :comments, as: :has_many, searchable: true
field :reviews, as: :has_many

field :files_attachments, as: :has_many

action ExportCsv

# filter PeopleFilter
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/app/controllers/avo/attachments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::AttachmentsController < Avo::ResourcesController
end

0 comments on commit 765fc62

Please sign in to comment.