HTML <span> nesting inside rails form_for label tag?
I want to insert an element inside the form_for label tag. I want to do this so that I can target a specific part of the label using CSS rules, in which case make the text red. From some quick reads, this is really valid HTML, and it fits my design, although the idea doesn't play happily with Rails.
The required html output is as follows:
<label for="zip">ZIP Code -<span class="required">Required</span></label>
My current code is as follows:
<%= form.label :zip, 'ZIP Code -<span class="required">Required</span>' %>
The problem is that Rails somehow avoids the internal span tag so that it appears as text on the page instead of HTML. I see this on the page:ZIP Code -<span class="required">Required</span>
Rails3 automatically escapes strings. You need to call #html_safe on the line that you put in the label. See http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/ for more details .