Is there any way from a controller to simply render an rhtml template into a string? Calling render or render_partial renders it directly into the HTTP response. The context: I''m trying to construct an e-mail (without using ActionMailer...and yes, I have good reasons for this) and I want to use a template to render part of the body of the e-mail. Cheers, Pete Yandell
On May 31, 2005, at 7:04 PM, Pete Yandell wrote:> Is there any way from a controller to simply render an rhtml > template into a string? Calling render or render_partial renders it > directly into the HTTP response. > > The context: I''m trying to construct an e-mail (without using > ActionMailer...and yes, I have good reasons for this) and I want to > use a template to render part of the body of the e-mail.You want render_to_string: http://api.rubyonrails.com/classes/ActionController/Base.html#M000164 Hope that helps, Jamis
On 01/06/2005, at 1:56 PM, Jamis Buck wrote:> On May 31, 2005, at 7:04 PM, Pete Yandell wrote: > >> Is there any way from a controller to simply render an rhtml >> template into a string? Calling render or render_partial renders >> it directly into the HTTP response. > > You want render_to_string: > > http://api.rubyonrails.com/classes/ActionController/ > Base.html#M000164OK, but how do I get the equivalent of the local_assigns parameter in render_partial? Or should I just set instance variables on the controller and then call render_to_string? Cheers, Pete Yandell
On Jun 1, 2005, at 12:48 AM, Pete Yandell wrote:> On 01/06/2005, at 1:56 PM, Jamis Buck wrote: > > >> On May 31, 2005, at 7:04 PM, Pete Yandell wrote: >> >> >>> Is there any way from a controller to simply render an rhtml >>> template into a string? Calling render or render_partial renders >>> it directly into the HTTP response. >>> >> >> You want render_to_string: >> >> http://api.rubyonrails.com/classes/ActionController/ >> Base.html#M000164 >> > > OK, but how do I get the equivalent of the local_assigns parameter > in render_partial? Or should I just set instance variables on the > controller and then call render_to_string?Yup, just set instance variables. In the latest-and-greatest rails (i.e., svn HEAD), you could do: result = render(:partial => "foo", :locals => {...}) erase_render_results But that won''t work with the currently released version. - Jamis