Check BOX problem


I am trying to make page with a list of users, with a check box next to
each of the user names.
The list of users is given by an array of users : @users

For eg: if @users has {user1, user2,user3} , my page should look like

user1 []
user2 []
user3 []

How can i achieve this? I went thru many howto’s esp to get confused and
depressed. Please help.

I tried using this:

check_box(“user”,, :checked => ‘checked’ )

<% end %>

<%= pagination_links(@user_pages) %>

check_box(“user”,, :checked => ‘checked’ ) in my rhtml. But it
gets printed directly :frowning:

Use “[]”'s to send it in the params as a hash like this:

<% @users.each do |user| -%>
<%= check_box(:user, :id, :name => “user[#{}]” -%>
<% end -%>

When this is sent back to the controller, you will have params[:user]
as a hash with user id’s as the keys and 1 as the value.

Sandeep G. wrote:

user2 []
check_box(“user”,, :checked => ‘checked’ )


William P.
[email protected]

2 things I forgot to mention. First, the method passed to check_box (:id
in the below example) is evaluated as an integer and any non-zero value
will check the box. Second, if you use an instance variable named the
same and the name of the checkbox, you can clean things up a bit like

<% for @user in @users -%>
<%= check_box “user[]”, :access_allowed? -%>
<% end -%>

This will achieve the same thing. This example assumes there is a method
for users that denotes whether they have access or not (and whether to
check the box or not). I’m just playing off your example.

William P. wrote:

user2 []
check_box(“user”,, :checked => ‘checked’ )


William P.
[email protected]

Thanks a Lot! This worked Great!