Height Select Box


/ Published in: Rails
Save to your folder(s)

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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.