You need to tell whatever generates your list of option tags which one
was selected. One way to do this is by passing a variable containing
the selected value and checking for that value when generating your
options. For instance, using a custom partial helper method:
# app.rb
helpers do
def partial(name, locals = {}, options = {})
options[:layout] = :none
options[:locals] ||= {}
options[:locals].merge! locals
haml name.to_sym, options
end
end
# select.haml
%select{ :id => '', :name => '' }
- if include_blank
%option= include_blank
- options_list.each do |option|
- value, text = option
%option{ :value => value, :selected => (value == selected_value) }
= text
# form.haml
= parital :select, :include_blank => 'choose
something...', :options_list => [[:one, 'One'], [:two, 'Two'],
[:three, 'Three']], :selected_value => :two
I didn't actually test this, so you may have to tweak it to get it
working. However this is basically how I would solve this problem.