Class: Studio::EmailsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Studio::EmailsController
- Defined in:
- app/controllers/studio/emails_controller.rb
Overview
/admin/emails — the standard transactional-email page every Studio app gets, modelled on the living style guide (/admin/style): a plain host-inherited controller whose view is a bare content wrapper, so it renders inside each host's application layout and picks up that app's navbar and theme.
It lists Studio::EmailImage's registry — one row per registered email, each showing its live banner and whether that banner is the INHERITED engine default or an APP-OWNED override — and writes an override through the shared crop modal. Replaces /admin/email_images, which now redirects here.
An app whose host never set Studio.s3_bucket_prefix cannot store an override. That is a read-only page, not an error: uploads_available? gates the write actions and the view explains why, so the page still shows what each email is currently sending.
Constant Summary collapse
- MAX_BYTES =
8.megabytes
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /admin/emails/:key — drop this app's override and fall back to the inherited default.
- #index ⇒ Object
-
#update ⇒ Object
PATCH /admin/emails/:key — upload/replace this app's own banner.
Instance Method Details
#destroy ⇒ Object
DELETE /admin/emails/:key — drop this app's override and fall back to the inherited default.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/studio/emails_controller.rb', line 46 def destroy # rescue_and_log, like #update: destroy is a WRITE path (it drops an # ImageCache row and deletes the S3 object behind it), and the bare rescue # below turns any failure into a friendly alert. Without the log that # failure is invisible — the admin sees "try again" and nothing reaches # ErrorLog to say why. rescue_and_log do reverted = Studio::EmailImage.revert(@key) notice = if reverted "#{Studio::EmailImage.label(@key)} reverted to the inherited default." else "#{Studio::EmailImage.label(@key)} was already using the inherited default." end redirect_to admin_emails_path, notice: notice, status: :see_other end rescue StandardError redirect_to admin_emails_path, alert: "Couldn't revert the image. Please try again.", status: :see_other end |
#index ⇒ Object
23 24 25 26 |
# File 'app/controllers/studio/emails_controller.rb', line 23 def index @entries = Studio::EmailImage.entries @uploads_available = Studio::EmailImage.uploads_available? end |
#update ⇒ Object
PATCH /admin/emails/:key — upload/replace this app's own banner.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/studio/emails_controller.rb', line 29 def update file = params[:image] unless valid_image?(file) = file.blank? ? "Choose an image to upload." : "Use a PNG, JPG, or WebP under 8 MB." return redirect_to admin_emails_path, alert: , status: :see_other end rescue_and_log do Studio::EmailImage.store(@key, io: file, content_type: file.content_type) redirect_to admin_emails_path, notice: "#{Studio::EmailImage.label(@key)} banner updated.", status: :see_other end rescue StandardError redirect_to admin_emails_path, alert: "Couldn't save the image. Please try again.", status: :see_other end |