undefined method `before_action' for ActionMailer

11,008

Solution 1

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

Solution 2

Check the beginning of your controller. Had a similar error where this...

  before_action :set_org, only: [:show, :edit, :update, :destroy]

got moved to above this accidently...

class OrgsController < ApplicationController

Move it back inside the class.

Share:
11,008
konclave
Author by

konclave

Updated on June 05, 2022

Comments

  • konclave
    konclave almost 2 years

    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.

  • Mindey I.
    Mindey I. over 10 years
    Is there a way to do something similar?
  • Swati Aggarwal
    Swati Aggarwal over 10 years
    @BrianArmstrong There's a way to implement this now. Refer accepted answer of stackoverflow.com/questions/17565784/…