Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rendering to a variable

I've been trying to get a dynamic nested form working with ajax in rails 3.

Originally I was following this example project and one of the helpers (add_task_link) looks really good, except that I can't seem to render a partial into a variable. I know that in a controller I can render_to_string, but not from a helper. It looks like in previous versions of rails it must have worked by just assigning the render call to a variable, but not any more.

Is there a workaround for this? I'm sure it must still be possible.

Thanks

like image 521
iwasinnamuknow Avatar asked May 03 '11 19:05

iwasinnamuknow


1 Answers

Use the capture method:

<% snippet = capture do %>
  <%= render :partial => 'some partial' %>
<% end %>

Later you can use the variable like this:

<%= snippet %>
like image 134
moritz Avatar answered Oct 21 '22 15:10

moritz