Use will_paginate to read the contents of the database and the realization of pa

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Operating environment: ruby2.0 rails4.0.0

Set the page has two kinds of methods, 1 add in Model self.per_page = 9; 2 directly added to the paginate: per_page => 9 parameters, the following are second ways:

Installing will_paginate 1
(1)Add gem "will_paginate" in the genfile file and execute
 $ bundle install

2 modified controller
def manage_index
    @user = User.paginate(page: params[:page], per_page: 9))

SQL statement generated as follows:
SELECT "users".* FROM "users" LIMIT 9 OFFSET 0
3 change the corresponding view file
     do |t|
        %td(align="center" style="width:37%" valign="middle")

        %td(align="center" style="width:37%" valign="middle")

        %td(align="center" style="width:45%" valign="middle")
          =link_to 'Delete' ,:action => "login"
          =link_to 'Change password',:action => "login"
  = will_paginate @user

This can be achieved by paging display.

Also on the database content to display screen: for example to display all users except the information outside the administrator can add restrictions
@user = User.paginate(page: params[:page], per_page: 9).where(:admin => 'false')

Implementation will generate SQL statements are as follows:
SELECT "users".* FROM "users" WHERE "users"."admin" = 'false' LIMIT 9 OFFSET 0
So the administrators to filter out
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Barret at December 08, 2013 - 9:18 PM