Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a select tag with rails with range of numbers with steps

What is the simplest way to write a rails select tag that will generate a select for the numbers 1-15 stepped in .5 increments?

I know this has to be simple but i'm struggling with the syntax, i know there has to be a more elegant way to write it than how i did.

thanks!

like image 489
Joel Grannas Avatar asked Jun 28 '12 14:06

Joel Grannas


2 Answers

select_tag "sizes", options_for_select((4..15).step(0.5))

This is how i wrote it... but is this the best way to approach?

also, if i wanted the 4.0/5.0/6.0 etc to read 4/5/6 as whole numbers, is there a way to do/include this on one line?

like image 116
Joel Grannas Avatar answered Oct 21 '22 23:10

Joel Grannas


select_tag "sizes", options_for_select( (4..15).step(0.5).map{|n| n%1 == 0 ? n.to_i : n} )
like image 27
Derek Hall Avatar answered Oct 21 '22 23:10

Derek Hall