5

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?

1 Answer 1

5

You'll already get only the ones that were checked; unchecked boxes aren't sent to the server.

Sign up to request clarification or add additional context in comments.

5 Comments

But how can I get them from just a single params? Just does not seems right to get it using a lot of params.
@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.)
Like if I name them :numbers[] and call params(:numbers) it will work?
@ArthurWilson The name shouldn't include the colon, but yes, I think so--why not just try it?
Actually I did 'numbers[]' and got the params as params[:numbers]. Thanks for the help.

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.