我只是installed the gem for will_paginate,它说它已成功安装。我跟着all the instructions与插件列出,我得到一个'未定义的方法`分页'错误。 Google搜索的方式找不到太多东西,并且无法自己修复(显然)。下面是代码:will_paginate未定义的方法错误 - Ruby on Rails
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 %>
UPDATE 我使用脚本/控制台来确定will_paginate是否正确安装,而不是。我必须添加:
config.gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter.org'
到/config/environments.rb文件并重新启动服务器。很棒。