Skip to content

Commit

Permalink
add preview image url to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Jan 30, 2024
1 parent 7a3e89c commit a582d39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def destroy
def serialize_params
{
include: { author: { only: %i[id email first_name last_name] },
documents: { only: %i[id uuid], methods: %i[url filename] } }
documents: { only: %i[id uuid], methods: %i[url preview_image_url filename] } }
}
end

Expand Down
4 changes: 4 additions & 0 deletions config/initializers/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
attribute :uuid, :string, default: -> { SecureRandom.uuid }

has_many_attached :preview_images

def preview_image_url
preview_images.joins(:blob).find_by(blob: { filename: '0.jpg' })&.url
end
end

ActiveStorage::LogSubscriber.detach_from(:active_storage) if Rails.env.production?
Expand Down

0 comments on commit a582d39

Please sign in to comment.