I'm writing some tests for my view helper (Rails 4.0) and trying to compile ERB code in a string that executes it. However, for the sake of simplicity, I am using a common method found in the rails form helpers here and receiving the same error:
Failure/Error: ERB.new(template).result
SyntaxError:
(erb):1: syntax error, unexpected ')'
...out.concat(( field_set_tag do ).to_s); _erbout.concat "\n\t\...
... ^
(erb):4: syntax error, unexpected end-of-input, expecting ')'
; _erbout.force_encoding(__ENCODING__)
^
This is the code I'm executing:
template = <<-TEMPLATE
<%= field_set_tag do %>
Lorem Ipsum
<% end %>
TEMPLATE
ERB.new(template).result
I've found some suggestions to use the <%
instead of <%=
but this results in Lorem Ipsum
being the only output. I've also tried using HAML instead of ERB but came out with similar results.
How can I get my template to output <fieldset>Lorem Ipsum</fieldset>
using the field_set_for
helper inside a string?