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.

On Jul 16, 6:03 am, wea_gruena <[email protected]> wrote:
> Hi,
> thanks a lot for your reply.
>
> I understand your comments about mixing of rails and haml code, but
> "include_blank" isn't my big problem.
>
> My problem is the "select mechanism", that means if I select an item
> and save, than this will be stored in the database (that's O.K.).
> But if I open the form again, the stored item will not pre-selected.
> Where is my mistake or how can I solve this ?

-- 
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Reply via email to