views:

93

answers:

3

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 }

how can i convert this into a select tag?

I tried:

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

but this is printing 10 11 12 13....100

+1  A: 

You almost had it:

<%=p.select :thc, options_for_select((10..100).step(10).to_a.map{|s| ["#{s}%", s]})%>
Jimmy Stenke
damn `to_a.map`
ratan
A: 

#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]})%>

Shtééf
A: 
<%= select("sale", "discount", (10..100).step(10).collect {|p| [ "#{p}%", p ] }, { :include_blank => true }) %>