Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

render partials in actionmailer templates

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

like image 898
badnaam Avatar asked Jun 20 '10 04:06

badnaam


People also ask

How do you render a partial?

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.

How should you use nested layouts in Rails?

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.

How can you tell Rails to render without a 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.


1 Answers

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'

like image 180
nvunguyen Avatar answered Sep 23 '22 05:09

nvunguyen