2012-07-17 37 views
1

我在Rails 3.2.1中有一個應用程序,它帶有一個名爲:options的序列化參數列的模型。rails fields_for標籤小寫

在我的表單中,我使用下面的代碼(它工作)列出用戶註冊時的選項。我需要爲此使用序列化選項,因爲我們需要在不同情況下捕獲不同的數據。

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

我使用<%=選項嘗試。標籤key.capitalize%>或<%= options.label key.titlecase%>無濟於事。看起來標籤標籤是罪魁禍首,而不是關鍵。在輸出代碼中,密鑰的情況很好。這就是標籤標籤中沒有的東西。

對此提出建議?提前致謝!

回答

2

如果你想在你的表格的所有標籤予以資本化,你可以只使用CSS:

label { text-transform: capitalize; } 
+0

感謝。這是一個很好的解決方法。 – ljfrench 2012-07-17 15:41:30

+0

我對這個問題遲到了,但對於其他任何人絆倒這個問題[this](https://stackoverflow.com/questions/6458635/stop-rails-form-label-from-modifying-text)的方法更多防呆。 – pdoherty926 2015-07-02 17:23:52