Hi all, I have a few problems with ActionMailer. First of all, I''ve used the script/generate mailer Norifier command, and it hasn''t created the view, just the model: from what I understand it should at least create an app/views/notifier/ directory, but I''m not sure ... BTW, I''ve followed the howto and I can''t make it work: # app/model/notifier.rb class Notifier < ActionMailer::Base def registration_mail(to, user, password) @recipients = to @from = "nicholas_wieland-whZMOeQn8C0@public.gmane.org" @subject = "Hi" @body = password end end This is how I use it in my controller: if @user.save Notifier.registration_mail( @params[''new_user''][''email''], @params[''new_user''][''username''], @params[''new_user''][''password'']) redirect_to :action => "registration_message" The view (app/views/notifier/registration_message.rhtml, I''ve created it by hand ...) is a simple test message, I just want to try out the whole thing. I''m sure that the method inside the controller is called because it redirects me to "registration_message". I''ve looked at my MTA logs and nothing has been sent. Do I have to require something inside the controller ? TIA, ngw -- checking for life_signs in -lKenny... no Oh my god, make (1) killed Kenny ! You, bastards ! nicholas_wieland-at-yahoo-dot-it
On Fri, 7 Jan 2005 16:33:57 +0100, Nicholas Wieland <nicholas_wieland-whZMOeQn8C0@public.gmane.org> wrote:> Hi all, I have a few problems with ActionMailer. > First of all, I''ve used the script/generate mailer Norifier command, and > it hasn''t created the view, just the model: from what I understand it > should at least create an app/views/notifier/ directory, but I''m not > sure ...Yes, and inside that directory you''d make a registration_mail.rhtml (the same name as your mailer) that is the body of your template. You also need to put the the body variables you want available to the template in a hash. So it would look something like this: def registration_mail(to, user, password) [...snip...] @body[password] = password @body[username] = username # this way you can have multiple variables passed to the template. end> > end > > This is how I use it in my controller: > > if @user.save > Notifier.registration_mail( > @params[''new_user''][''email''], > @params[''new_user''][''username''], > @params[''new_user''][''password'']) > redirect_to :action => "registration_message" > > The view (app/views/notifier/registration_message.rhtml, I''ve created it > by hand ...)You don''t actually call the registration_mail method directly. You would call it as: Notifier.deliver_registration_mail(...) This method is created automatically by ActionMailer. It''s mentioned here in the ActionMailer README: http://am.rubyonrails.org/files/README.html (Directly above the ''Dependencies'' header) When called this it uses the template with the same name as the mailer method automatically. You don''t need to call ''redirect_to'' (which would redirect the users browser instead of sending a mail anyway). Hope that helps. -- Xian
- Christian Metts :> When called this it uses the template with the same name as the mailer > method automatically. You don''t need to call ''redirect_to'' (which > would redirect the users browser instead of sending a mail anyway).I use redirect_to to redirect the user to a message, not to send the mail :)> Hope that helps.Yes, thank you, everything is clear now, I''ve missed the deliver_* part of the documentation, sorry. HAND, ngw -- checking for life_signs in -lKenny... no Oh my god, make (1) killed Kenny ! You, bastards ! nicholas_wieland-at-yahoo-dot-it