Problem with Check box tag


#1

Hai
Just started to learn Ruby on Rails
I have a list of users displayed as rows and towards each row there is a
check box. There is a “Select All” , and “Approve” buttons. On clicking
the Select All button I want to check all the check boxes or can check
the boxes separtely if don’t want to check all the boxes and then after
submitting the Approve button wish to change the status of the selecteds
users(which users whose check box is checked) to approved. Pls give me
suggestions in doing this.
Thanks in advance


#2

Indu Rs wrote:

Hai
Just started to learn Ruby on Rails
I have a list of users displayed as rows and towards each row there is a
check box. There is a “Select All” , and “Approve” buttons. On clicking
the Select All button I want to check all the check boxes or can check
the boxes separtely if don’t want to check all the boxes and then after
submitting the Approve button wish to change the status of the selecteds
users(which users whose check box is checked) to approved. Pls give me
suggestions in doing this.
Thanks in advance

Do you have any code examples? One whay to do what you are saying what I
think you are saying, is to have a check_box connected with a
remote_function that hits the controller, does some stuff and then
returns to update a div. I use the remote_function to update a single
user in my app or, like what you are trying to do, multiple users. By
doing it this way you can update a single div without having to reload
the page.


#3

Shandy N. wrote:

Indu Rs wrote:

Hai
Just started to learn Ruby on Rails
I have a list of users displayed as rows and towards each row there is a
check box. There is a “Select All” , and “Approve” buttons. On clicking
the Select All button I want to check all the check boxes or can check
the boxes separtely if don’t want to check all the boxes and then after
submitting the Approve button wish to change the status of the selecteds
users(which users whose check box is checked) to approved. Pls give me
suggestions in doing this.
Thanks in advance

Do you have any code examples? One whay to do what you are saying what I
think you are saying, is to have a check_box connected with a
remote_function that hits the controller, does some stuff and then
returns to update a div. I use the remote_function to update a single
user in my app or, like what you are trying to do, multiple users. By
doing it this way you can update a single div without having to reload
the page.

Hai
Thank you for the reply.
here is my sample code of view

<th> <%= submit_tag "Select All", :onclick=>"return check_all()" %> 
<% count = 0 %> <%= form_tag :controller=>"user",:action=>"list_users"%> <% for user in @users %> <% count = count + 1%> <% end %> <%= hidden_field_tag "h_id" ,count %>

User list

Name User Name Address Country Language
<%=link_to user.name,:controller=>"User",:action=>"edit", :id=>user.id %> <%= user.username %> <%= user.address %> <%= user.country.name %> <%= user.language.language %> <%= check_box_tag "user_status"+count.to_s,user.id%>
<%= will_paginate @users %>
<%= submit_tag "Approve", :controller=>"user" ,:action=>"list_users",:class=>"test"%>

and in my controller I tried this one

def list_users

if !(params[:search].blank? and params[:country_id].blank?)
if request.post? and params[:commit] == “Search”
@users =
User.search(params[:search],params[:country_id],params[:page])
else

@users = User.paginate :page=>params[:page],:per_page => 2

end
else
@users = User.paginate :page=>params[:page],:per_page => 2
end
if @users.blank?
flash[:notice] = ‘No Records Found.’
end

if request.post? and params[:commit] == "Approve"
     params[:user_status].each do |ln|
         @user = User.find(ln)
           @user.update_attribute(:user_status,1)
     end

end

end
Now if selected users separately(not by using the “Select All”
button) the status of the selected users are changing. But the “Select
All” button is not working. ie when clicking on the “Select All” button
only the first one in the list is selecting

and in my javascript i wrote
function check_all() {
var count = document.getElementById(‘h_id’).value;
for(i=1;i<=count;i++){
document.getElementById(‘user_status’+i).checked = true
}
return false;
}
what is the problem with this one? pls give suggestion.