2

I'm porting an application to Rails 3.

We're an e-commerce site and naturally we send copies of tax invoices by email. We use plain text, so a .text.erb seems logical.

We also display invoices in an area of the user profile, inside <pre></pre> tags. Is there are way I can share a partial between plain text mailer templates, and views in HTML? If I try to render "shared/invoice" inside my HTML ERB template, it says the partial doesn't exist, and that's because it's a .text.erb partial.

What are my options, without duplicating code?

d11wtq
  • 34,788
  • 19
  • 120
  • 195

1 Answers1

2

I haven't tried this in Rails 3, but in Rails 2 you could specify the format of the partial. Might be worth giving it a go on Rails 3.

render :partial => "shared/invoice.text.erb"
Dave A-R
  • 1,159
  • 1
  • 11
  • 22
  • Any idea if I can escape that content? Obviously the .text.erb doesn't escape characters like `<`, so they are being interpreted as HTML here. Is there an inverse of `html_safe`? – d11wtq Jul 08 '11 at 13:05
  • I'm not sure, but you could try wrapping it in html_escape – Dave A-R Jul 08 '11 at 13:10
  • 1
    Hackalicious: `<%= "" + render("shared/invoice.text.erb") %>`. I'll have to move this to a `render_text` helper for clarity. – d11wtq Jul 08 '11 at 13:11