Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Last active March 24, 2016 09:10
Show Gist options
  • Save LolWalid/06422f5525908e6b6567 to your computer and use it in GitHub Desktop.
Save LolWalid/06422f5525908e6b6567 to your computer and use it in GitHub Desktop.
Why can I call method as class one but I have to define it as instance method in mailer?
Mailer.send_mail('subject', 'message')
class Mailer < ActionMailer::Base
def send_mail(subject, message)
subject = subject
@message = message
mail(to: '[email protected]', subject: subject)
end
end
# https://github.com/rails/rails/blob/master/actionmailer/lib/action_mailer/base.rb
module ActionMailer
class Base < AbstractController::Base
class << self
protected
def method_missing(method_name, *args) # :nodoc:
if action_methods.include?(method_name.to_s)
MessageDelivery.new(self, method_name, *args)
else
super
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment