`
kong1616
  • 浏览: 101587 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics