所以我正在运行一个带有捆绑器的rails 2.3.11应用程序,而我正在努力让will_paginate工作。它返回以下错误:
#< Class:...
的未定义方法`paginate'def show
@category = Category.find_by_url_name(params[:id])
@brands = @category.brands.find(:all, :order => "name")
@categories = Category.find(:all)
@meta_title = "#{@category.name}"
respond_to do |format|
format.html do |wants|
@brand = @brands.first
@products = Product.paginate(:page => params[:page], :per_page => 6, :conditions => ['brand_id = ? AND category_id = ?', @brand.id, @category.id])
render :template => 'brands/show'
end
format.xml { render :xml => @category }
end
end
这是我的控制器动作。完整的错误:
NoMethodError in CategoriesController#show
undefined method `paginate' for #<Class:0x1034703e8>
RAILS_ROOT: /Users/tjs/Sites/emeraldcg
Application Trace | Framework Trace | Full Trace
/Users/tjs/.rvm/gems/ruby-1.8.7-p352/gems/activerecord-2.3.11/lib/active_record/base.rb:1998:in `method_missing'
/Users/tjs/Sites/emeraldcg/app/controllers/categories_controller.rb:28:in `show'
/Users/tjs/Sites/emeraldcg/app/controllers/categories_controller.rb:25:in `show'
Request
Parameters:
{"id"=>"acoustic-guitars"}
Show session dump
Response
Headers:
{"Content-Type"=>"text/html",
"Cache-Control"=>"no-cache"}
我的gemfile很直接:
# A sample Gemfile
source "http://rubygems.org"
# gem "rails"
gem "rails", '2.3.11'
gem "rake"
gem "RedCloth", ">=4.2.2"
gem "will_paginate", "~> 2.3.16"
group :development do
gem "mysql"
gem "capistrano"
gem "capistrano-ext"
end
group :test do
gem "sqlite3"
end
我会理解,如果这是因为它是一个数组而失败但是为什么它作为一个类方法失败了?
感谢您的帮助。
答案 0 :(得分:2)
过去那里有一些will_paginate和Rails 2的问题,请尝试更新到最新版本的op_paginate。同时你可以试试这个:
@products = Product.all.paginate(:page => params[:page], :per_page => 6, :conditions => ['brand_id = ? AND category_id = ?', @brand.id, @category.id])
答案 1 :(得分:0)
您无法在模型上调用paginate。它可以在集合上调用,如散列,数组,ActiveRecord。