1

我正在使用 rails 3.2.13,运行正常的 sphinx 服务器,在我安装 will_paginate gem 分页后无法正常工作。

错误是:

 NoMethodError in DashboardsController#search

undefined method `paginate' for #<ThinkingSphinx::Search:0x000000046a9650>
app/controllers/dashboards_controller.rb:12:in `search'

这是我的仪表板控制器的代码

class DashboardsController < ApplicationController    
  def search
    query=[]
    query << "#{params[:property_listing]}" if(params[:property_listing]).present?
    query << "#{params[:property_type]}" if(params[:property_type]).present?
    query << "#{params[:city]}" if(params[:city]).present?
    query << "#{params[:sale_price]}" if(params[:sale_price]).present?
    @properties = Property.search("*#{query}*").paginate(:page=>params[:page], :per_page=>5)
    @json = @properties.to_gmaps4rails
    respond_to do |format|
      format.html
    end
  end
end

搜索.html.erb

<% @properties.each do |property| %>
 //some codes which is working fine before using pagination
<% end %>
<%= will_paginate(@properties) %>

我已经安装了宝石

gem 'will_paginate','>= 3.0.pre'

结果不显示,我做错了什么?

4

1 回答 1

1

您应该使用Thinking Sphinx 的分页

@properties = Property.search("*#{query}*", :page=>params[:page], :per_page=>5)    
于 2013-09-27T14:44:12.727 回答