Return to Snippet

Revision: 23426
at February 7, 2010 10:59 by 67ideas


Updated Code
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

Revision: 23425
at February 7, 2010 10:43 by 67ideas


Initial Code
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.invert.sort
end

Initial URL

                                

Initial Description
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.

Initial Title
Height Select Box

Initial Tags
forms

Initial Language
Rails