Created
September 5, 2008 02:17
-
-
Save JonCrawford/8917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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