Class: Studio::EmailImagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/studio/email_images_controller.rb

Overview

Admin page to manage the banner image on transactional emails (Studio

EmailImage). One managed variant today (magic_link); the registry is the extension point. Shared by every app — surfaced from each app’s admin hub.

Constant Summary collapse

MAX_BYTES =
8.megabytes

Instance Method Summary collapse

Instance Method Details

#indexObject



10
11
12
# File 'app/controllers/studio/email_images_controller.rb', line 10

def index
  @variants = Studio::EmailImage.variants
end

#updateObject

PATCH /admin/email_images/:variant — upload/replace a banner.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/studio/email_images_controller.rb', line 15

def update
  variant = params[:variant].to_s
  return head :not_found unless Studio::EmailImage.known?(variant)

  file = params[:image]
  unless valid_image?(file)
    message = file.blank? ? "Choose an image to upload." : "Use a PNG, JPG, or WebP under 8 MB."
    return redirect_to admin_email_images_path, alert: message, status: :see_other
  end

  rescue_and_log do
    Studio::EmailImage.store(variant, io: file, content_type: file.content_type)
    redirect_to admin_email_images_path, notice: "#{Studio::EmailImage.label(variant)} banner updated."
  end
rescue StandardError
  redirect_to admin_email_images_path, alert: "Couldn't save the image. Please try again.", status: :see_other
end