ruby-on-rails-3actionmailerbefore-filter

undefined method `before_action' for ActionMailer


Trying to attach file to mail via before_action filter:

class UserMailer < ActionMailer::Base
  before_action :add_logo_attachment

  layout 'mail'
  default from: "\"Admin\" <admin@site.com>",
      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.


Solution

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