Hi,
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
below.
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”, user.id, :checked => ‘checked’ )
<% end %>
<%= pagination_links(@user_pages) %>
check_box(“user”, user.id, :checked => ‘checked’ ) in my rhtml. But it
gets printed directly
Use “[]”'s to send it in the params as a hash like this:
<% @users.each do |user| -%>
<%= check_box(:user, :id, :name => “user[#{user.id}]” -%>
<% 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”, user.id, :checked => ‘checked’ )
–
Sincerely,
William P.
http://www.billpratt.net
[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
this
<% 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”, user.id, :checked => ‘checked’ )
–
Sincerely,
William P.
http://www.billpratt.net
[email protected]
Thanks a Lot! This worked Great!