Skip to content

Instantly share code, notes, and snippets.

@JonCrawford
Created September 5, 2008 02:17
Show Gist options
  • Save JonCrawford/8917 to your computer and use it in GitHub Desktop.
Save JonCrawford/8917 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment