我只是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文件並重新啓動服務器。很棒。