undefined method `before_action' for ActionMailer

konclave picture konclave · Jul 4, 2013 · Viewed 10.4k times · Source

Trying to attach file to mail via before_action filter:

class UserMailer < ActionMailer::Base
  before_action :add_logo_attachment

  layout 'mail'
  default from: "\"Admin\" <[email protected]>",
      to: Proc.new {Admin.pluck(:email)}

  def send_mail
    mail(subject: 'Hello, admin!')
  end
  .
  .
  private

  def add_logo_attachment
    attachments.inline['logo.png'] = File.read(Rails.root.join('app/assets/images/logo.png'))
  end

end

And I get this error: undefined method `before_action' for UserMailer:Class There is the same example in Rails guides and I can't understand what's the difference between my code and the code in guides.

Answer

konclave picture konclave · Jul 4, 2013

There's no callbacks for ActionMaler::Base in Rails 3