【发布时间】:2011-11-21 15:13:48
【问题描述】:
我只是 installed the gem 为 will_paginate 并且它说它已成功安装。我关注了插件中列出的all the instructions,我收到了一个“未定义的方法‘分页’错误”。在 Google 搜索中找不到太多东西,而且我自己也无法修复(显然)。代码如下:
PostsController
def index
@tag_counts = Tag.count(:group => :tag_name, :order => 'updated_at DESC', :limit => 10)
@posts = Post.paginate :page => params[:page], :per_page => 50
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
format.json { render :json => @posts }
format.atom
end
end
/model/post.rb
class Post < ActiveRecord::Base
validates_presence_of :body, :title
has_many :comments, :dependent => :destroy
has_many :tags, :dependent => :destroy
cattr_reader :per_page
@@per_page = 10
end
/posts/views/index.html.erb
<%= will_paginate @posts %>
更新 我使用脚本/控制台来确定 will_paginate 是否正确安装,但不是。我不得不补充:
config.gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter.org'
到 /config/environments.rb 文件并重新启动服务器。效果很好。
【问题讨论】:
标签: ruby-on-rails ruby pagination