Sha256: 5f8480a0384ad8f7a87d3047210c395c5d8f598822017b4ae18f64e7a8bd48e7

Contents?: true

Size: 705 Bytes

Versions: 2

Compression:

Stored size: 705 Bytes

Contents

module CustomEmailTracker
  class EmailOpensController < ActionController::Base
    def track_open
      token = params[:token]

      email_open = TrackedEmail.find_by(token: token)
      if email_open.present?
        email_open.opened_at = Time.zone.now
        email_open.save
      end


      # Serve a 1x1 pixel image
      # send_file Rails.root.join('app/assets/images/pixel.png'), type: 'image/png', disposition: 'inline'

      pixel_image_path = File.join(__dir__, 'pixel.png')

      if File.exist?(pixel_image_path)
        send_file pixel_image_path, type: 'image/png', disposition: 'inline'
      else
        render plain: "Image not found", status: :ok
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
custom_email_tracker-0.1.2 app/controllers/custom_email_tracker/email_opens_controller.rb
custom_email_tracker-0.1.1 app/controllers/custom_email_tracker/email_opens_controller.rb