【问题标题】:will_paginate undefined method error - Ruby on Railswill_paginate 未定义的方法错误 - Ruby on Rails
【发布时间】:2011-11-21 15:13:48
【问题描述】:

我只是 installed the gem 为 will_paginate 并且它说它已成功安装。我关注了插件中列出的all the instructions,我收到了一个“未定义的方法‘分页’错误”。在 Google 搜索中找不到太多东西,而且我自己也无法修复(显然)。代码如下:

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 %>

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

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

到 /config/environments.rb 文件并重新启动服务器。效果很好。

【问题讨论】:

    标签: ruby-on-rails ruby pagination


    【解决方案1】:

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

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

    效果很好。简单的修复。

    【讨论】:

      【解决方案2】:

      由于我错误地将 . . .

      gem 'will_paginate'
      

      。 . .命令在 Gemfile 中的错误位置。确保将它放置在所有运行时环境都可以使用的位置——不要嵌套在包中以用于分区环境,例如:

      group :test do
      .
      .
      .
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-05
        • 1970-01-01
        • 2022-11-19
        • 2012-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多