Rails 搜索中分页问题

Unknow user · October 24, 2012 · Last by rubynewbie replied at October 24, 2012 · 2175 hits

做一个简单的产品搜索,并且使用 Kaminari 做分页, 可是@Products= Product.page(params[:page]).per(7) 这个是正常的, 但是加了条件搜索后会报错,undefined method `current_page'

Products_controller.rb

if params[:min_price] || params[:max_price] @Products=.Product.page(params[:page]).per(7).find(:all,:conditions => ["price >= ? AND price <= ? ",params[:min_price],params[:max_price]]) else @Products= Product.page(params[:page]).per(7) end

修改成下面试试

@Products=.Product.where("price >= ? AND price <= ? ",params[:min_price],params[:max_price]]).page(params[:page]).per(7)
Unknow user #1 October 24, 2012

#1 楼 @reyesyang 这个也试过了,一搜索后出现的报错是 undefined method `page' for []:Array

You need to Sign in before reply, if you don't have an account, please Sign up first.