2017-07-20 4 views
0

私のRailsフォームの選択フィールドにカスタム名を追加したいとします。フィールドは、time_zone_selectフォームオプションヘルパーを使用して生成されます。私は'name'=>'squad_cycle[start_time][0]'をtime_fieldとdate_fieldフォームヘルパーと一緒に使っていましたが、これはうまくいきましたが、これはtime_zone_selectでは機能しません。Railsフォームのtime_zone_selectフィールドにカスタム名を追加する

以下

は私のERBです:

<%= f.date_field :start_date, 'name'=>'squad_cycle[start_date][0]' %> 
<%= f.time_field :start_time, 'name'=>'squad_cycle[start_time][0]' %> 
<%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones, default: 'Eastern Time (US & Canada)' %> 

HTML出力:

<input name="squad_cycle[start_date][0]" type="date" id="squad_cycle_start_date"> 
<input name="squad_cycle[start_time][0]" type="time" id="squad_cycle_start_time"> 
<select name="squad_cycle[time_zone]" id="squad_cycle_time_zone">...</select> 
+0

で続きを読みますhttp://api.rを確認してくださいubyonrails.org/v5.1/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-time_zone_select 'html_options'は' name: 'your_custom_name'を与えることができる引数です –

答えて

1

あなたは次のようにあなたのHTMLオプションを追加する必要があります。

<%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones, { default: 'Eastern Time (US & Canada)' }, { name: 'my_custom_name' } %> 

APIDock

+1

それはありがとう! – ev662

関連する問題