I am trying to use an existing partial in an actionmailer template, something like..
My merchant_offer.txt.html.erb
<%= render :partial => "offers/offer", :locals => {:offer => @offer} %>
Notifier.rb (my mailer class):
def merchant_offer(offer)
subject "New Offer from #{offer.merchant.name}"
from "[email protected]"
recipients xxx@
sent_on Time.now
body :offer => offer
end
The offer partial in in another view folder called offers
But it throws a missing tempalate error.
Is there a way to re-use existing view partial in in mailer tempalates?
Thanks
Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html.
Nesting layouts is actually quite easy. It uses the content_for method to declare content for a particular named block, and then render the layout that you wish to use. So, that's the normal application layout.
2.2. By default, if you use the :plain option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option and use the . text. erb extension for the layout file.
You should be able to render partial from mailer templates.
I believe the error is in your merchant_offer view. Try renaming 'merchant_offer.txt.html.erb' to 'merchant_offer.html.erb'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With