I’m having some trouble figuring this one out:
I have a multiple select box. Selecting one option, the value gets
submitted just fine. Selecting two or more options, it’s only the last
selected that get’s submitted.
Why?
How are you using the select box? Are you tying it right to the model
class?
If so this isn’t going to work (that I know of).
Your tag should look something like:
..
Of course with all the other stuff needed as well. You'll notice the
name is
basically an array name which will allow you to pass as many values as
you
want for this option and can get it by doing something like
params[:my_options][0].
I had a similar problem yesterday, even the same perhaps?
My guess is that it is in fact submitting all the values as an array but
you are not seeing it selected in the form because all the values in the
array are strings and not numbers.
What I did was before using the array in “selected_value” I turned all
the elements in the array to integers using to_i
Yeah it helped a lot - I didn’t know you had to put [] on the name of
the input tag.
Well I actually have another problem, because I’m using the multiple
select in a form that’s an AJAX observe_form. I’m not sure how to pass
the selected values in the :with parameter.