0
我有一个表单,我希望选择下拉列表以显示选项0-41。我试着下面的代码,但它不工作:在Rails中选择选项标记
<%= f.select :years_together, 42.times do |year| %>
<%= year %>
<% end %>
UPDATE
其实,我想选择显示“不到一年”的值为零,“超过40”为41.值
我有一个表单,我希望选择下拉列表以显示选项0-41。我试着下面的代码,但它不工作:在Rails中选择选项标记
<%= f.select :years_together, 42.times do |year| %>
<%= year %>
<% end %>
UPDATE
其实,我想选择显示“不到一年”的值为零,“超过40”为41.值
我认为你需要调用options_for_select
:
<%= f.select :years_together, options_for_select(41.times { |year| year }) %>
看起来像这样的工作:<%= f.select:years_together,options_for_select(41.times .map {| year |年})%> – mikeglaz
哎呀忘了'地图'...很酷! –