2010-04-15 111 views
2

我只是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文件并重新启动服务器。很棒。

回答

2

我使用脚本/控制台来确定will_paginate是否正确安装,而不是。我不得不补充:

config.gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter. 

伟大的工程。简单的修复。

2

我遇到了will_paginate gem(使用Rails 3)的未定义方法错误,因为我错误地放置了。 。 。

gem 'will_paginate' 

。 。 。命令在Gemfile中的错误位置。确保将其放置在所有运行时环境可用的位置 - 不是嵌套在分区环境的捆绑包中,例如:

group :test do 
. 
. 
. 
end 
相关问题