简体   繁体   English

will_paginate未定义方法错误-Ruby on Rails

[英]will_paginate undefined method error - Ruby on Rails

I just installed the gem for will_paginate and it says that it was installed successfully. 我刚刚为will_paginate 安装了gem ,它说安装成功。 I followed all the instructions listed with the plugin and I am getting an 'undefined method `paginate' for' error. 我按照插件列出的所有说明进行操作 ,但出现了“未定义的方法'paginate'”错误。 Can't find much in the way of Google search and haven't been able to fix it myself (obviously). 无法以Google搜索的方式找到很多东西,也无法自己解决(很明显)。 Here is the code: 这是代码:

PostsController 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 /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 /posts/views/index.html.erb

  <%= will_paginate @posts %>

UPDATE I used the script/console to determine if will_paginate was correctly installed properly and it wasn't. 更新我使用脚本/控制台来确定will_paginate是否正确安装,是否正确。 I had to add: 我必须添加:

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

to the /config/environments.rb file and restart the server. 到/config/environments.rb文件,然后重新启动服务器。 Works great. 效果很好。

I used the script/console to determine if will_paginate was correctly installed properly and it wasn't. 我使用脚本/控制台来确定will_paginate是否正确安装,是否正确。 I had to add: 我必须添加:

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

works great. 效果很好。 Simple fix. 简单修复。

I experienced an undefined method error with the will_paginate gem (using Rails 3) because I mistakenly placed the . 我用will_paginate gem遇到了未定义的方法错误(使用Rails 3),因为我错误地放置了。 . .

gem 'will_paginate'

. . . command in the wrong place in Gemfile. 命令在Gemfile中的错误位置。 Make sure you have it placed where it will be available to all runtime environments--not nested inside a bundle for a partitioned-off environment such as: 确保将其放置在所有运行时环境都可以使用的位置,而不是嵌套在捆绑的环境中,例如:

group :test do
.
.
.
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM