diff --git a/app/controllers/api/templates_controller.rb b/app/controllers/api/templates_controller.rb index 3a83ad42..8329fbe8 100644 --- a/app/controllers/api/templates_controller.rb +++ b/app/controllers/api/templates_controller.rb @@ -52,7 +52,7 @@ module Api 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 diff --git a/config/initializers/active_storage.rb b/config/initializers/active_storage.rb index ac62272d..53530786 100644 --- a/config/initializers/active_storage.rb +++ b/config/initializers/active_storage.rb @@ -4,6 +4,10 @@ ActiveSupport.on_load(:active_storage_attachment) do 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?