ljfrench
ljfrench

Reputation: 23

rails fields_for label lowercase

I have an application in Rails 3.2.1 with a model which has a column of serialized params called :options.

In my form, I am using the following code (and it works) to list the options when the user is registering. I need to use the serialized options for this because we will need to capture different data in different circumstances.

<% @options.each do |key, value| %>
    <%= f.fields_for :options do |options| %>
        <%= options.label key %> 
        <%= options.text_field key, :value => value %>
    <% end %> 
<% end %>

The code works fine, but the field labels are coming out in lowercase instead of preserving their case: 1) street address

<label for="registration_options_2)_City_State,_Zip">2) city state, zip</label>
<input id="registration_options_2)_City_State,_Zip" name="registration[options][2)_City_State,_Zip]" size="30" type="text" value="" />

<label for="registration_options_3)_Contact_phone_number">3) contact phone number</label>
<input id="registration_options_3)_Contact_phone_number" name="registration[options][3)_Contact_phone_number]" size="30" type="text" value="" />

I've tried using <%= options.label key.capitalize %> or <%= options.label key.titlecase %> to no avail. It appears the label tag is the culprit and not the key. As in the output code, the key's case is fine. It's what comes out of the label tag that's not.

Suggestions? Thanks in advance!

Upvotes: 1

Views: 1317

Answers (1)

ply
ply

Reputation: 1141

If you want all labels in your forms to be capitalized you could just use css:

label { text-transform: capitalize; }

Upvotes: 2

Related Questions