开发者

rendering to a variable

开发者 https://www.devze.com 2023-03-03 03:24 出处:网络
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 ca

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 vari开发者_开发技巧able, but not any more.

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

Thanks


Use the capture method:

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

Later you can use the variable like this:

<%= snippet %>
0

精彩评论

暂无评论...
验证码 换一张
取 消