Nesting HTML <span> inside rails form_for label tag?

I want to nest a element inside a form_for label tag. I want to do this so I can target a specific portion of the label with CSS rules, in this case to make the text red. From some quick reading, this does appear to be valid HTML, and it fits with my design even though the idea is not playing happily with Rails.

The desired html output is like this: <label for="zip">ZIP Code -<span class="required">Required</span></label>

My current code looks like this: <%= form.label :zip, 'ZIP Code -<span class="required">Required</span>' %>

The problem is that Rails is somehow escaping the inner 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>

Answers


Rails3 automatically escapes strings. You need to call #html_safe on the string you're putting in the label. See http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/ for details.


Need Your Help

CodeIgniter: Form values to model function

model-view-controller forms function codeigniter send

I'm pretty new to the MVC structure and I wan't to do things so close to right as possible. Thats why I ask this question.

Multilingual Site in Zend Framework

php zend-framework multilingual zend-translate

i am working on a site to include Multilingual Support.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.