NewMonarch (owner)

Revisions

gist: 8917 Download_button fork
public
Public Clone URL: git://gist.github.com/8917.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def optgroups_with_options(groups, options, selected = nil, prompt = nil)
      return "<option>Error: Sizes don't match.</option>" if groups.size != options.size
      str = String.new
      unless prompt.nil?
        if prompt.is_a? String
            str += content_tag :option, prompt, :value => ""
        elsif prompt.is_a? Array
            str += content_tag( :option, prompt[0], :value => prompt[1])
        end
      end
      (0..groups.size-1).each do |i|
         str += content_tag :optgroup, options_for_select(options[i], selected), :label => groups[i]
      end
      str
end
 
# How it's called...
def position_options(selected = nil, prompt = nil)
      groups = ["Front Tshirt", "Back Tshirt", "Other"]
      options = [
         ["Full Front","Center Chest","Left Breast","Right Breast", "Lower Left", "Lower Right", "Lower Center"],
         ["Full Back","Upper Back","Lower Back","Left Shoulder", "Right Shoulder"],
         ["Left Sleeve","Right Sleeve","Left Side", "Right Side", ["Other (Explain in notes)", "Other"] ]
      ]
      optgroups_with_options(groups, options, selected, prompt)
end