Change your controller as follows.
def index
@q = Household.search(params[:q])
@households = @q.result.page(params[:page]).per(5)
end
문제
I am Using Ransack with Kaminari - My Controller is:
def index
@q = Household.search(params[:q])
@households = @q.result
end
The relevant part of my view:
- @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
This give me an error:
undefined method `current_page' for #<ActiveRecord::Relation:0x007fd4cd3a0b98>
If I change
= paginate @households
to
= paginate households
I am OK but I only get pagination when I execute a search, when I have a blank I don't get any pagination - I am using decent exposure which is allowing my household instead of @household
해결책
Change your controller as follows.
def index
@q = Household.search(params[:q])
@households = @q.result.page(params[:page]).per(5)
end