Hi there, how can I tell my Rails app Mailer to: -> Apply a specific "view" when I send out an *email* ? When I don''t specify anything specific, my "WhateverMailer" looks for its "view" (.erb file) as if the Mailer was a Controller (following the same standard logic: ../app/views/ directory). But I need my WhateverMailer to go find the .erb file on a different path - but how and where to tell it to?? Thanks a lot for any help! Tom -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Vandenabeele
2009-Mar-04 16:01 UTC
Re: How to apply a specific "view" when I send out an *email*
On Wed, Mar 4, 2009 at 4:17 PM, Tom Ha <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tom Ha
2009-Mar-04 16:28 UTC
Re: How to apply a specific "view" when I send out an *email*
Very cool - thanks a lot, Peter! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---