Q:

Use of Helper not displaying HTML content [Ruby on Rails]

I am trying to create a form using the following view file
<%= form_for :spec do |form| %>
<fieldset>
<legend><%= @title %></legend>

<%= text_field_for form, "first_name" %>
<%= text_field_for form, "last_name" %>
<div class="form_row">
<label for="gender">Gender: </label>
<%= radio_button :spec, :gender, "Male" %> Male
<%= radio_button :spec, :gender, "Female" %> Female
<%= radio_button :spec, :gender, "Other" %> Other
</div>
<div class="form_row">
<label for="birthdate">Birthdate:</label>
<%= date_select :spec, :birthdate,
            :start_year => Spec::START_YEAR,
            :end_year => Time.now.year,
            :include_blank => true,
            :order => [:month,:day,:year] %>
</div>
<%= text_field_for form, "occupation" %>
<%= text_field_for form, "city" %>
<%= text_field_for form, "state" %>
<%= text_field_for form, "zip_code", Spec::ZIP_CODE_LENGTH %>

<%= submit_tag "Update", :class => "submit" %>
</fieldset>

<%end%>

And I am using the following helper method
def text_field_for (form, field, 
            size=HTML_TEXT_FIELD_SIZE, 
            maxlength=DB_STRING_MAX_LENGTH)
    label = content_tag("label","#{field.humanize}:", :for => field)
    form_field = form.text_field field, :size => size, :maxlength => maxlength
    content_tag("div", "#{label} #{form_field}", :class => "form_row")
end

However, my output gives HTML code for  
<label for="first_name">First name:</label> <input id="spec_first_name" maxlength="255" name="spec[first_name]" size="15" type="text" />
<label for="last_name">Last name:</label> <input id="spec_last_name" maxlength="255" name="spec[last_name]" size="15" type="text" />

instead of textfields and labels
Can anyone suggest a solution for this? 

A:

Update text_field_for method as below:
def text_field_for (form, field, 
            size=HTML_TEXT_FIELD_SIZE, 
            maxlength=DB_STRING_MAX_LENGTH)
    label = content_tag("label","#{field.humanize}:", :for => field)
    form_field = form.text_field field, :size => size, :maxlength => maxlength
    content_tag "div", label + form_field,  :class => "form_row" 
end

You were treating the label and form_field as String. You shouldn't be interpolating them.

