3

我正在使用带有 Kaminari 的 Ransack - 我的控制器是:

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

4

1 回答 1

7

如下更改您的控制器。

def index 
  @q = Household.search(params[:q])
  @households = @q.result.page(params[:page]).per(5)
end
于 2013-07-04T06:17:19.743 回答