Rails paginate 分页插件

rails老版本是包含pagination的,但是新的版本需要作为plugin安装了,
官方 : http://wiki.github.com/mislav/will_paginate/
gem install will_paginate

然后在config/environment.rb的尾部(init后)载入:
require “will_paginate”

需要重启web server,
在action中:

      def index
      @posts = Post.paginate :page => params[:page],:order => 'created_at DESC', :per_page => 10
      end
然后在views加入:
      will_paginate @posts
      Total:

其他用法举例:
      self.paginate(:conditions => fcon, :include => [:department],:order => ["created_at DESC"], :page => page, :per_page => 30)
      self.paginate_by_sql ["SELECT idc_infos.*, SUM(idc_contracts.bandwidth_amount) total_bandwidth, SUM(idc_contracts.asset_amount) total_asset, SUM(idc_contracts.server_amount) total_server FROM idc_infos LEFT JOIN idc_contracts ON idc_infos.id = idc_contracts.idc_id GROUP BY idc_infos.id ORDER BY idc_infos.disp_ord DESC "], :page => page, :per_page => 30

你可能感兴趣的:(sql,Web,SQL Server,Rails)