Forum: Ruby on Rails Working with after_create and Mailer Class

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eric M. (Guest)
on 2009-01-31 19:18
(Received via mailing list)
I am trying to setup sending confirmation emails after creating a new
instance of Project.  In my Project Model, I have an after_create
callback that calls the method send_confirmation.  This is working
fine -- the method is called, but I haven't figured out how to pass
along the current instance object to the Mailer class I've created.

I had assumed that instance variables were accessible from within the
Project Model, even if created inside of the Project Controller.  The
code below results in error "nil.name undefined".  So how do I get the
mailer to know of the current instance object in order to send an
email using its attributes.

Probably doing something stupid.  Thanks in advance.

Project Model:

after_create :send_confirmation

def send_confirmation
  Mailer.deliver_confirm(@project)
end

Mailer Class:

def confirm(project)
...
  subject    project.name
...
end
Eric M. (Guest)
on 2009-01-31 19:39
(Received via mailing list)
Nevermind, I figured it out.  Definitely a "duh" moment.  From within
the class, using self points to the current instance.

Thanks,
Eric
This topic is locked and can not be replied to.