Rails dies when I try to call a method from my Mailer. But I have
defined my method. What could I have missed? Here is the irb session:
p = Person.find(1)
=> Person data…
SiteMailer.request_admin_approval§
NoMethodError: undefined method `request_admin_approval’ for
SiteMailer:Class
SiteMailer.method_defined? :request_admin_approval
=> true
The method code:
class SiteMailer < ActionMailer::Base
def request_admin_approval(person)
@subject = ‘Watercooler - New User Notification’
@body[“person”] = person
@recipients = “me”
@from = ‘[email protected]’
@sent_on = Time.now
@headers = {}
end
Taylor S. wrote:
Rails dies when I try to call a method from my Mailer. But I have
defined my method. What could I have missed? Here is the irb session:
The method code:
class SiteMailer < ActionMailer::Base
def request_admin_approval(person)
#…
end
To call your mail methods, you dont call them directly:
SiteMailer.deliver_request_admin_approval(person)
Which sends the email and returns a TMail object.
On Fri, 2007-04-06 at 22:42 +0200, Taylor S. wrote:
SiteMailer.method_defined? :request_admin_approval
@recipients = “me”
@from = ‘[email protected]’
@sent_on = Time.now
@headers = {}
end
try ‘self’
def self.request_admin_approval(person)
–
Craig W. [email protected]
On 4/6/07, Taylor S. [email protected] wrote:
SiteMailer:Class
SiteMailer.method_defined? :request_admin_approval
=> true
It is true… there is a method named request_admin_approval for
SiteMailer… but it is an instance method (as in:
s = SiteMailer.new
s.request_admin_approval§
)
You’re trying to access it as a class method… which means, you would
need
to define self.request_admin_approval in the SiteMailer class instead of
just request_admin_approval.
Or, you will have to make an instance of your SiteMailer object in order
to
call the function.
The method code: