how to build a select tag from a range in rails

后端 未结 4 2486
太阳男子
太阳男子 2021-02-20 02:37

I want to have a drop down that consists of values 10% 20% 30% so on till 100.

In ruby It can be done by

(10..100).step(10) { |i| p i }
4条回答
  •  耶瑟儿~
    2021-02-20 03:40

    #step returns an enumerator (or yields, as you've shown). It looks like what you want is to call #collect on this enumerator.

    <%=p.select :thc, options_for_select((10..100).step(10).collect {|s| ["#{s}%", s]})%>

提交回复
热议问题