rails字段表示标签小写



我在Rails 3.2.1中有一个应用程序,它的模型有一列序列化的参数,名为:options。

在我的表单中,当用户注册时,我使用以下代码(它很有效)来列出选项。我需要使用序列化选项,因为我们需要在不同的情况下捕获不同的数据。

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

代码运行良好,但字段标签是小写的,而不是保留大小写:1) 街道地址

<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="" />

我已尝试使用<%=options.label关键字大写%>或<%=options.label key.titlecase%>无效。标签标签似乎是罪魁祸首,而不是关键。与输出代码一样,键的大小写也很好。标签标签中的内容不是。

建议?提前感谢!

如果你想让表单中的所有标签都大写,你可以使用css:

label { text-transform: capitalize; }

最新更新