Rails checkbox and params
10,557
You'll already get only the ones that were checked; unchecked boxes aren't sent to the server.
Author by
Arthur Wilson
Updated on June 04, 2022Comments
-
Arthur Wilson about 2 years
I am using many checkboxes in a page as the following:
<%= check_box_tag(:one, value = 1) %></p>
Imagine that it goes from 1 to 20, all the same with the value changed. How can I get in the controller the
params
of the ones that were checked?Example: If user checks 3, 5 and 10 how can I get just those params in a single params?
-
Arthur Wilson over 12 yearsBut how can I get them from just a single params? Just does not seems right to get it using a lot of params.
-
Dave Newton over 12 years@ArthurWilson Not sure what you mean. If they're all named the same thing don't they come as an array? (I don't recall off the top of my head, sorry.)
-
Arthur Wilson over 12 yearsLike if I name them
:numbers[]
and callparams(:numbers)
it will work? -
Dave Newton over 12 years@ArthurWilson The name shouldn't include the colon, but yes, I think so--why not just try it?
-
Arthur Wilson over 12 yearsActually I did
'numbers[]'
and got the params asparams[:numbers]
. Thanks for the help.