8
votes

How can I render a partial to a String in Ruby on Rails 4.2, since render_to_string is deprecated?

Something like:

 rendered_string = render_to_string partial: 'forgotten_orders/soonest_manufacturing_date', locals: { forgotten_order: forgotten_order, soonest_manufacturing_date: soonest_manufacturing_date }
2

2 Answers

13
votes

You can just use render. My demo:

In my view:

<% foo = render 'foo_thing', bar:"formal bar" %>
<%= foo %>

In _foo_thing.html.erb:

<%= "This bar is a #{bar}" %>

And on my screen:

 This bar is a formal bar 
0
votes

Well, render_to_string actually is not deprecated, it still exists. The implementation however has changed according to the render_to_string doc. I haven't really used it in a while, but I'd expect it to still work for you.