与kaminari和mongoid的分页

时间:2016-04-04 14:01:15

标签: ruby-on-rails mongoid kaminari

我有这个问题



undefined method `total_pages' for #<Mongoid::Criteria:0x00000002651d80>
&#13;
&#13;
&#13;

的Controler

&#13;
&#13;
@services = Service.paginate(:page => params[:page], :per_page => 3)
&#13;
&#13;
&#13;

视图

&#13;
&#13;
<% paginate @services %>
&#13;
&#13;
&#13;

mongo不会返回对象。

2 个答案:

答案 0 :(得分:0)

的Controler

&#13;
&#13;
class	ServicesController < ApplicationController
	def index
		#@services = Service.order(name: :asc)
		@organs = Admin::Organ.all
		@services = Service.paginate(:page => params[:page], :per_page => 3)
	
	end
end
&#13;
&#13;
&#13;

&#13;
&#13;
<% pagination @services %>
&#13;
&#13;
&#13; ERRO

&#13;
&#13;
undefined method `total_pages' for #<Mongoid::Criteria:0x00000002651d80>
&#13;
&#13;
&#13;

是这个

答案 1 :(得分:0)

在kaminari,你必须 使用以下语法

 Service.page(params[:page].to_i).per(3)

而不是

 Service.paginate(:page => params[:page], :per_page => 3)

这是will_paginate

的语法