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

1 Answer 1

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 %>
Sign up to request clarification or add additional context in comments.

1 Comment

If you are getting params['values'] as an array on page replace @user.stores.map {|j| j.store_id} with params['values']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.