On Wed, Mar 4, 2009 at 4:17 PM, Tom Ha
[email protected] wrote:
how can I tell my Rails app Mailer to:
→ Apply a specific “view” when I send out an email ?
The trick is
body render_message(channel, "")
in app/models/…_mailer.rb (example below).
So, a few hints from my code (changed some parts for censuring
the internal business logic, so may be inexact, sorry upfront for that)
In the app/controllers/mail_controller.rb
def handle_email
…
case preview_or_send
when :preview
@email = ChannelMailer.create_channel_mail(details, @channel)
when :send
delivery_state = “OK”
begin
@email = ChannelMailer.deliver_channel_mail(details, @channel)
rescue
delivery_state = “FAIL”
logger.info “FAILED mail delivery, email = #{@email}”
end
…
fill_log_entry @email, delivery_state, details, @channel
end
…
end
In app/models/channel_mailer.rb
class ChannelMailer < ActionMailer::Base
def channel_mail(details, channel)
subject “censured”
from FROM
sent_on Time.now
case channel
when "censured"
to_list = ...
bcc_list = ...
...
end
set_recipients(to_list, bcc_list)
body render_message(channel, "") # ###### This is the real
answer to your question
…
end
…
end
In app/view/channel_mailer/
$ ls -1
_details_for_channel.erb
channel_1.erb
channel_2.erb
channel_3.erb
HTH,
Peter