Invalid characters in label_tag
I am creating a simple form in ERB, but the HTML generated by the text_field tag invalidates the for attribute in the tag tag.
<div>
<p><%= label_tag "email[name]", "Name" %></p>
<%= text_field :email, :name, :class => "text_field" %>
</div>
Produces HTML
<div>
<p><label for="email[name]">Name</label></p>
<input class="text_field" id="email_name" name="email[name]" size="30" type="text" />
</div>
This results in the error
character "[" is not allowed in attribute value "for".
How to generate text without the name of the nested parameter name [name] to change the label tag for an attribute? Is there an alternative approach that produces valid HTML?
0
source to share
2 answers