我正在使用Ransack和Kaminari - 我的控制器是:
def index
@q = Household.search(params[:q])
@households = @q.result
end
我的观点的相关部分:
- @households.each do |household|
%tr
%td= link_to household.household_name, edit_household_path(household)
%td= household.box
%td= household.thumbs.html_safe
%td= household.neighbors.count
%td= household.visits.count
%td= household.last_visit
%td
= link_to 'Edit', edit_household_path(household), class: 'btn'
= link_to 'Destroy', household, confirm: 'Are you sure?', method: :delete, class: 'btn btn-mini btn-danger'
= paginate @households
这给我一个错误:
undefined method `current_page' for #<ActiveRecord::Relation:0x007fd4cd3a0b98>
如果我改变
= paginate @households
到
= paginate households
我很好,但是当我执行搜索时,我只有分页,当我有空白时我没有任何分页 - 我正在使用体面的曝光,这允许我的家庭而不是@household
答案 0 :(得分:6)
按如下方式更改控制器。
def index
@q = Household.search(params[:q])
@households = @q.result.page(params[:page]).per(5)
end