views:

62

answers:

3

User is a model. I have 100 users.

I need to present the list of all users so that admin can check or uncheck a user and then do something with it. The problem is that when the the form is submitted then on the server side I get person_1, person_2, person_3 etc. Handling these params could be problematic.

Is there a way so that on the server side I get params like

person[1], person[2], person[3]

I think I need to do something like

check_box :person[],....

I am not sure where to put the [] .

A: 

Have you tried anything like

check_box_tag "person[]", ...
neutrino
A: 

I think perhaps a better way would be to pass an array of people that were checked. To do that, you want your generated html to look something like this:

<input type="checkbox" id="people[]" value="1">
<input type="checkbox" id="people[]" value="2">
<input type="checkbox" id="people[]" value="3">
...

The code to generate that might look something like this, using Rails form helpers:

<% 1.upto(@max_user_id) do |id| %>
     check_box_tag("people[]", id)
<% end %>

The controller that handles the form action would then have access to params['people'], which would be an array of all the ids that were checked.

John Hyland
A: 

try this. it works for me.

File.all.each do |file| 
  tmp = "file[#{file.id}]" 
  check_box_tag tmp 
end
Neeraj Singh