是否可以生成0到100作为select_tag的选择?

时间:2013-01-23 08:58:04

标签: ruby-on-rails ruby-on-rails-3

我现在输入字段就像这段代码一样 但我想制作选择标签,我可以在其中选择从0到100的数字 有没有办法轻松生成选择标签?

<%= f.number_field :age %>

4 个答案:

答案 0 :(得分:4)

如下所示:

<%= f.select :age, (0..100).to_a.map{|n| [n, n]} %>

答案 1 :(得分:1)

select("user[]", "age", 0..100.to_a.map{|n| [n, n]}, {}, { :index => nil })

f.select :age, options_for_select( 0..100.to_a.map{|n| [n, n]}, @object.age )

答案 2 :(得分:1)

 <%= f.select("person", "age", [1..100], { :include_blank => true })%>

答案 3 :(得分:0)

<%= f.select :age, options_for_select((0..100).to_a) %>
相关问题