This project is archived and is in readonly mode.
Emails with attachments don't work as documented
Reported by Justin French | February 11th, 2009 @ 04:11 AM | in 2.x
Trying to send an email which has both a plain text body and a file attachment, as shown in the documentation for ActionMailer, but the local assigns are nil when the body view is rendered.
Have been speaking with Koz about this elsewhere for a little while and we decided to add it here as a ticket instead.
I've attached a full sample app, but here's the mailer:
class Mail < ActionMailer::Base
def daily_report
recipients "me@example.com"
subject "Daily Report"
from "me@example.com"
content_type "multipart/alternative"
part :content_type => "text/plain",
:body => render_message("daily_report", :date => Time.now, :recipient => "Bob")
attachment :content_type => "text/csv", :filename => "hello", :body => "my,cool,csv"
end
end
And the view:
<%= @recipient %>,
Please see the attached report, created for <%= @date.strftime("%Y %m %d") %>.
An error is raised on nil.strftime, which I think means the local assigns are not working as advertised.
Comments and changes to this ticket
-
Michael Koziarski February 11th, 2009 @ 04:14 AM
- Milestone cleared.
I can reproduce the breakage for mail.zip here as well.
However the attached patch shows that the tests pass when we test that functionality. So something is very strange.
-
Justin French February 11th, 2009 @ 04:16 AM
- no changes were found...
-
Michael Koziarski February 11th, 2009 @ 04:18 AM
- Assigned user changed from Michael Koziarski to josh
I can confirm this error, but everything on the AM side seems 'right'. Any ideas josh? Can you reproduce the error with the zip file?
-
josh February 16th, 2009 @ 08:07 PM
- State changed from new to open
- Assigned user changed from josh to Michael Koziarski
I can confirm the error in the sample app.
I'm not sure how to fix it, but it looks like the error is around this line.
# Then, if there were such templates, we check to see if we ought to # also render a "normal" template (without the content type). If a # normal template exists (or if there were no implicit parts) we render # it. template_exists = @parts.empty? template_exists ||= template_root["#{mailer_name}/#{@template}"] @body = render_message(@template, @body) if template_exists
The template renders fine the first time with the explicit render_message. Because "daily_report.erb" exists, it is setting template_exists to true and trying to render the template a second time.
-
Michael Koziarski February 17th, 2009 @ 01:41 AM
Yeah, it seems it's missing a performed? style check. But I'm not sure that we can change that too easily without potentially breaking people who are reying on the implicit rendering of the body?
-
Michael Koziarski February 22nd, 2009 @ 02:32 AM
- Milestone set to 2.x
It's had this problem all along, so I'll punt on this for now.
-
Jeremy Kemper April 24th, 2010 @ 10:09 PM
- State changed from open to resolved
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>