I am unable to generate a message body using ActionMailer 3. This problem occurs even for ActionMailer classes and views that are unchanged from Rails-2.3. When these files are run with Rails 2.3 emails with bodies result. When exactly the same files are used in a Rails 3 project the headers are produced but no body. I am at a loss to explain this. Initially I thought that maybe the API had changed in such a fashion as to drop the old template naming convention. However, having reworked these files to use the new api exactly the same behaviour is observed, only headers are produced. The new files are app/mailers/forex_mailer.rb and app/views/forex_mailer/forex_cacb_update_notice.plain.erb app/mailers/forex_mailer.rb contains this method def forex_cacb_update_notice( rates, to_address = ''xxxx-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org'', fm_address = ''yyyy-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org'' ) ... mail( :to => recipients, :from => fm_address, :subject => subject ) The call used to invoke this mailer is: ForexMailer.forex_cacb_update_notice(rates, send_to).deliver I therefore suspected that there must be something that has changed in how the templates are parsed. So, taking a hint from the API Readme I changed the name of the template files from x.plain.rb to x.text.plain.rb. This had no effect. As these templates are a mixture of fixed text and interpolated ruby values I expected that I should see at least the fixed text portions of the templates in the message body, but I am seeing nothing at all. Inspection of the deliveries array shows this: #<Mail::Message:23533088849320, Multipart: false, Headers: <Date: Mon, 25 Oct 2010 14:16:22 -0400>, <From: forex.control-fqAF1SpE7daWxEb2tNKyrg@public.gmane.org>, <To: forex.test-fqAF1SpE7daWxEb2tNKyrg@public.gmane.org>, <Message-ID: <4cc5c9769f540_1b3b156736d7d9b4140a6-06T4xRAtGxQzD4KH/4NhZn6gBdUqRO3WexnE27lsaYT6gbPvEgmw2w@public.gmane.org>>, <Subject: [ForEx] 2010-10-25 - Foreign Exchange Rates Central Bank Update Notice>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>> #<Mail::Body:0x2ace72cd5878 @raw_source="", @epilogue=nil, @charset="US-ASCII", @preamble=nil, @encoding="7bit", @parts=[], @boundary=nil, @part_sort_order=["text/plain", "text/enriched", "text/html"]> #<Mail::Body:0x2ace72cd5878 @raw_source="", @epilogue=nil, @charset="US-ASCII", @preamble=nil, @encoding="7bit", @parts=[], @boundary=nil, @part_sort_order=["text/plain", "text/enriched", "text/html"]> Does anyone have any idea why the message body is not being generated from the templates provided? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
James Byrne
2010-Oct-25 18:45 UTC
Re: ActionMailer 3 does not generate a body from template
I generated the new mailer using the rails3 rails g mailer name idiom. So, I assumed that the fact that a directory app/views/name indicated where I should put the template files. However, removing this directory has absolutely no effect on ActionMailer. At the very least I would expect it to raise a missing template error. But no, it behaves exactly as it has all along. It creates headers but no body. So, where is it looking for the templates and why on earth does it not fail if it cannot find them? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
James Byrne
2010-Oct-25 19:02 UTC
Re: ActionMailer 3 does not generate a body from template
However, if I specify the template by calling the mail method with a do block and providing a render call to a non-existent template then I do get a template missing error raised. What is going on here? The API clearly states that if the mail method is called without a block then app/views are searched (presumably in a directory with the same name as the mailer class) for any files having the same stem name as the mailer method and ending in erb. So, why no template error when the directory is missing? I find that if I pass a block to the mail method and specify my template therein then, and only then, is the email body generated. Is this the expected behaviour? If so then the documentation is sadly misleading. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.