0

I want to keep the select_tag(:multiple => true) options to be selected which were selected by user once search is performed

<%= select_tag 'values[]', method_for_options_for_select, :class => 'some-class', :multiple => true, :size => 6 %>

Suppose a user select 4 values from the select tag then for values should be selected, How can we pass this 4 values to the select_tag?

I tried using :selected => params['values[]'] but this doesnt works for multiple true

Any help will be appreciated

Said Kaldybaev
  • 9,380
  • 8
  • 36
  • 53
user2406618
  • 144
  • 1
  • 2
  • 12

1 Answers1

0

Ref this and options_for_select

Something like following

<%= select_tag 'values[]', 
options_for_select(@stores.map {|s| [s.store_name, s.store_id]}, 
@user.stores.map {|j| j.store_id}),
:class => 'some-class', :multiple => true, :size => 6 %>
Community
  • 1
  • 1
Salil
  • 46,566
  • 21
  • 122
  • 156
  • 1
    If you are getting params['values'] as an array on page replace `@user.stores.map {|j| j.store_id}` with `params['values']` – Salil Jul 09 '13 at 10:44