Kaminari:未定义的方法 total_pages

Kaminari : undefined method total_pages

我在 Kaminari 上遇到问题 Rails 4.

这是我的renters_controller.rb

def search
  @location = params[:search]
  @distance = params[:km]
  @renters = Renter.near(@location, 30000).order("distance")
  @renters = @renters.page(params[:page])

  if @renters.empty?
    @renters = Renter.all
    search_map(@renters)
  else
    search_map(@renters)
  end
end

和我的观点 search.html.haml。

.row
  = paginate @renters

和我的错误信息

Started GET "/search?utf8=%E2%9C%93&search=" for ::1 at 2016-03-17 09:37:59 +0100
Processing by RentersController#search as HTML
Parameters: {"utf8"=>"✓", "search"=>""}
(0.5ms)  SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "renters" WHERE (false) LIMIT 25 OFFSET 0) subquery_for_count
Renter Load (0.9ms)  SELECT "renters".* FROM "renters"
Rendered renters/search.html.haml within layouts/application (8.2ms)
Completed 500 Internal Server Error in 23ms (ActiveRecord: 1.5ms)

ActionView::Template::Error (undefined method `total_pages' for #<Renter::ActiveRecord_Relation:0x007fd4d36bdc30>):
1: .row
2:   = paginate @renters
app/views/renters/search.html.haml:2:in `_app_views_renters_search_html_haml__3667517883215455359_70276042599600'

在控制器中,如果我写

就可以了
@renters = Renter.page(params[:page])

有什么想法吗?

试试这个,我希望它能奏效。

def search
  @location = params[:search]
  @distance = params[:km]
  @renters = Renter.near(@location, 30000).order("distance")

  if @renters.empty?
    @renters = Renter.all
    search_map(@renters)
  else
    search_map(@renters)
  end
  @renters = @renters.page(params[:page])
end