/ Published in: Rails
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.
It allows heights between 4 feet and 7 feet. To change these limits, change 48 and 84 to some other numbers.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def height_options heights = Hash.new for n in 48..84 feet = (n/12).floor inches = n % 12 heights[n] = "#{feet}'#{inches}''" end return heights.to_a.sort.map { |h| h.reverse } end