Posted By

67ideas on 02/07/10


Tagged

select forms ActionView


Versions (?)

Height Select Box


 / Published in: Rails
 

Put the heightoptions method into a helper file, and use it as the select collection for select or collectionselect.

It allows heights between 4 feet and 7 feet. To change these limits, change 48 and 84 to some other numbers.

  1. def height_options
  2. heights = Hash.new
  3.  
  4. for n in 48..84
  5. feet = (n/12).floor
  6. inches = n % 12
  7. heights[n] = "#{feet}'#{inches}''"
  8. end
  9.  
  10. return heights.to_a.sort.map { |h| h.reverse }
  11. end

Report this snippet  

You need to login to post a comment.