2

I am doing an online contract agreement which is generated dynamically based on the current state of our contract language (stored in an ERB partial).

When the user clicks "I Agree" we save the variable data, but I also want to store the contents of the rendered partial (html fragment) in the database.

I tried using ActionView::Helpers::CaptureHelper.capture -- wrapping the whole partial in a block and rendering at the end, like

<% @saved_output = capture do %>
...
The rest of the erb with instance variable <%= @my_class.name %> and so on
...
<% end %>
<%= @saved_output %>
<% logger.debug "Rendered output is: #{@saved_output}" %>

And this produced the same result and also sent the correct text to the log. But it appears to go out of scope -- even if I declare @saved_output = nil prior to render it's nil when I end the block.

I tried using content_for as well ... which makes some sense to me, but ... huh, just not getting it. Any helpful pointers appreciated.

4

1 回答 1

3

render_to_string您在创建记录时是否尝试过控制器?这可能允许您继续并“快照”页面。

于 2012-10-18T03:43:48.187 回答