Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to build a select tag from a range in rails

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

like image 965
ratan Avatar asked Feb 10 '10 18:02

ratan


1 Answers

You almost had it:

<%=p.select :thc, options_for_select((10..100).step(10).to_a.map{|s| ["#{s}%", s]})%>
like image 119
Jimmy Stenke Avatar answered Sep 24 '22 00:09

Jimmy Stenke