doug wrote:
� @recipients = params[:to_email]
� blah blah blah
end
Phillip –
Your basic solution is better than mine. My solution works; but, it’s
not as elegant as yours. Therefore, I want to use yours. The only
thing is, when using your solution I can’t seem to access params from
the mail template. Could you please extend your example by telling me
what I need to do to access params from the mail template? Thanks.
... doug
Hi Doug,
No problem. Access to values in the template has to go through the @body
global in the model method. Basically, you assign a hash key/value to
@body for whatever you want to access in the template. For example, I
might do something like
def some_email(params)
@subject = “Some Subject”
@recipients = params[:to_email]
@from =
@sent_on = Time.now # you might want to use TimeZone for this, though
@headers = {}
@body[:name] = params[:name]
@body[:email] = params[:email]
@body[:group] = params[:group]
@body[:description] = params[:description]
@body[:comments] = params[:comments]
end
then in the template, I’d have access to globals
@name
@email
@group
@description
@comments
Again, you’re dealing with standard hashes and objects, so you can pass
anything into the @body hash. Many times, I do something like
def some_email(user)
@body[:user] = user
end
and in the template, use the methods on my User model
@user.first_name
@user.full_name
or whatever.
Hope that helps clear it up for you. I also discovered a tricky little
feature of mailer templates, which I described here
http://per-snicket-y.blogspot.com/2007/12/actionmailer-and-mail-templates.html
It might also be of interest to you.
Peace,
Phillip