Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails will_paginate未定义方法错误-Ruby on Rails_Ruby On Rails_Ruby_Pagination - Fatal编程技术网

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

Ruby on rails will_paginate未定义方法错误-Ruby on Rails,ruby-on-rails,ruby,pagination,Ruby On Rails,Ruby,Pagination,我只是为will_paginate写的,上面说它安装成功了。我跟随了插件的列表,我得到了一个“未定义的方法”“paginate”“for”error。在谷歌搜索的方式中找不到太多,而且我自己也无法修复它(显然)。代码如下: 后置控制器 def index @tag_counts = Tag.count(:group => :tag_name, :order => 'updated_at DESC', :limit => 10) @posts = Post.pag

我只是为will_paginate写的,上面说它安装成功了。我跟随了插件的列表,我得到了一个“未定义的方法”“paginate”“for”error。在谷歌搜索的方式中找不到太多,而且我自己也无法修复它(显然)。代码如下:

后置控制器

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

转到/config/environments.rb文件并重新启动服务器。非常好。

我使用脚本/控制台确定will_paginate是否正确安装。我必须补充:

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

效果很好。简单的修复

我在will_paginate gem(使用Rails 3)中遇到了一个未定义的方法错误,因为我错误地将

gem 'will_paginate'
。命令在文件中的错误位置。确保将其放置在可供所有运行时环境使用的位置,而不是嵌套在已分区环境的捆绑包中,例如:

group :test do
.
.
.
end
group :test do
.
.
.
end