分页不适用于合并对象

时间:2017-04-14 14:10:36

标签: ruby-on-rails merge pagination

我有4个对象

@ob1 = User.where(:area => "India")
@ob2 = User.where(:area => "USA")
@ob3 = User.where(:area => "UK")
@ob4 = User.where(:area => "China")

合并对象上的4个对象

@merged_obj= @obj1+@obj2

合并对象并传递给分页

@users = @merged_obj.paginate(:page => params[:page], :per_page => 1)

但是低谷错误

NoMethodError: undefined method `paginate' for #<Array:0x007fc3d65a5338>

分页与以下代码一起使用:

@users = User.where(:area => "India").paginate(:page => params[:page], :per_page => 1)

宝石: -

gem 'will_paginate', '~> 3.1.0'
gem 'will_paginate-bootstrap'

1 个答案:

答案 0 :(得分:1)

看起来它不能使用数组。请执行以下任何操作

@obj = User.where(:area => ["India","USA","UK","China"])

@merged_obj = User.where(id: [@ob1.id, @ob2.id, @ob3.id, @ob4.id])

编辑:如果对区域进行非规范化不是一个选项,请回复评论在阵列上做自己的分页

@page = @merged_obj[start, pagesize]