require "base64" class MailOpensController < ActionController::Base PIXEL = Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==").freeze def show record_open expires_now response.set_header("Cache-Control", "no-store, no-cache, must-revalidate, private, max-age=0") response.set_header("Pragma", "no-cache") send_data PIXEL, type: "image/gif", disposition: "inline", filename: "o.gif" end private def record_open token = params[:token].to_s recipient = MailingRecipient.find_by(tracking_token: token) recipient&.record_open! rescue StandardError => e Rails.logger.warn("[mail_open] #{e.class}: #{e.message}") raise if Rails.env.test? end end