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.
<table width="100%" border="1">
<tr><td colspan="6"
align="center"><h3>User list</h3></td>
</tr>
  <tr>
    <th>Name</th>
    <th>User Name</th>
    <th>Address</th>
    <th> Country</th>
    <th>Language</th>
    <th> <%= submit_tag "Select All",
:onclick=>"return check_all()" %>
</th>
  </tr>
  <% count = 0 %>
<%= form_tag
:controller=>"user",:action=>"list_users"%>
<% for user in @users %>
<% count = count + 1%>
  <tr>
    <td align="center"><%=link_to
user.name,:controller=>"User",:action=>"edit",
:id=>user.id %></td>
    <td align="center"><%= user.username %></td>
    <td align="center"><%= user.address %></td>
    <td align="center"><%= user.country.name %></td>
    <td align="center"><%= user.language.language %>
    <td> <%= check_box_tag
"user_status"+count.to_s,user.id%>
  </tr>
<% end %>
<%= hidden_field_tag "h_id" ,count %>
<tr><td colspan="6" align="center">
<%= will_paginate @users %><br>
<%= submit_tag "Approve", :controller=>"user"
,:action=>"list_users",:class=>"test"%>
</table>
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;
}
Pleas help in solving this problem
Thanks in advance
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
bala kishore pulicherla
2008-Oct-15  08:07 UTC
Re: More than one check boxes and selecting all the check boxes
hi u can try this way
in ur view the check_box likee
<th> Select All
 <input id="check_all" name="check_all"
type="checkbox"
onclick="Form.getInputs(''users'',
''checkbox'').each(function(box){box.checked
= $(''check_all'').checked})" />
 <th>
and in the user loop
<input type="checkbox" class="check"
name="user_status[]" value="<%user.id%>" />
and in ur controller...
for user in params[:user_status]
          puts user
###'' should be able get the all the user ids that are selected
      end
hope it will help u.
:) Bala
On Wed, Oct 15, 2008 at 1:18 PM, Indu RS
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>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.
>
> <table width="100%" border="1">
> <tr><td colspan="6"
align="center"><h3>User list</h3></td>
> </tr>
>  <tr>
>    <th>Name</th>
>    <th>User Name</th>
>    <th>Address</th>
>    <th> Country</th>
>    <th>Language</th>
>
>    <th> <%= submit_tag "Select All",
:onclick=>"return check_all()" %>
> </th>
>
>  </tr>
>  <% count = 0 %>
> <%= form_tag
:controller=>"user",:action=>"list_users"%>
> <% for user in @users %>
> <% count = count + 1%>
>  <tr>
>    <td align="center"><%=link_to
> user.name,:controller=>"User",:action=>"edit",
:id=>user.id %></td>
>    <td align="center"><%= user.username %></td>
>    <td align="center"><%= user.address %></td>
>    <td align="center"><%= user.country.name
%></td>
>    <td align="center"><%= user.language.language %>
>    <td> <%= check_box_tag
"user_status"+count.to_s,user.id%>
>  </tr>
> <% end %>
> <%= hidden_field_tag "h_id" ,count %>
> <tr><td colspan="6" align="center">
> <%= will_paginate @users %><br>
> <%= submit_tag "Approve", :controller=>"user"
> ,:action=>"list_users",:class=>"test"%>
> </table>
>
> 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;
> }
> Pleas help in solving this problem
> Thanks in advance
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Indu RS
2008-Oct-15  09:09 UTC
Re: More than one check boxes and selecting all the check boxes
Bala kishore Pulicherla wrote:> for user in params[:user_status] > puts user > ###'' should be able get the all the user ids that are selected > end > > > hope it will help u. > > :) Bala > On Wed, Oct 15, 2008 at 1:18 PM, Indu RSThank you so much for the immediate response and solved my issue -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---