In our rails 3.2
app, our view code (in simple_form) is stored in @erb_code
and render it with inline as:
<%= simple_form_for @project do |f| %>
<%= render inline: ERB.new(@erb_code).result(binding) %>
<% end %>
@erb_code
is a string which stores the view code. There is a fields_for
block in @erb_code which causes error. Here is the fields_for block:
.........
<%= f.simple_fields_for :contract do |builder| %>
<%= render('contract', :f => builder)%>
<% end %>
........
Here is the error:
(erb):17: syntax error, unexpected ')'
...ds_for :contract do |builder| ).to_s); _erbout.concat " ...
... ^
(erb):21: syntax error, unexpected end-of-input, expecting ')'
...ut.force_encoding(__ENCODING__)
...
)
and .to_s
were added after |builder| when rendering and those cause the error. Is it escape issue? If it is, how to escape |builder|
and/or any other in ERB.new()
?
Please try the following:
<%= simple_form_for @project do |f| %>
<%= render inline: @erb_code, locals: {f: f} %>
<% end %>
i.e., without using ERB.new. Add more locals as the need be.
In past I have used render inline for similar purposes in Rails 3.2.13.