我只是在用一个简单的留言板玩 Ruby on Rails 3.0,发现 will_paginate 有几个问题。
最紧迫的是,每次显示新页面时,都会对主题中的每个帖子进行数据库查询。
可以想象,如果您有一个包含 10,000 多个帖子的主题,这将非常缓慢。
有没有办法阻止这种奇怪的行为?
显示控制器:
@posts=@topic.posts
@posts = Post.paginate @posts, :page => params[:page],:order => "post_number"
模型
cattr_reader :per_page
@@per_page = 20
看法
<%= will_paginate @posts %>