Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/sinatra/support/htmlhelpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def h(str)
#
# select_options([['One', 1], ['Two', 2]])
# select_options([['One', 1], ['Two', 2]], 1)
# select_options([['One', 1], ['Two', 2]], [1,2])
# select_options([['One', 1], ['Two', 2]], 1, '- Choose -')
#
# # using it with the provided date helpers...
Expand All @@ -45,7 +46,9 @@ def select_options(pairs, current = nil, prompt = nil)
pairs.unshift([prompt, '']) if prompt

pairs.map { |label, value|
tag(:option, label, :value => value, :selected => (current == value))
selected = (current == value) if current.is_a? String
selected = (current.include? value) if current.is_a? Array
tag(:option, label, :value => value, :selected => selected )
}.join("\n")
end

Expand Down