Rails + Sunspot:使用日期范围查询方面时出现“未定义的方法`populate_instances'...”错误

时间:2011-11-29 15:10:17

标签: ruby-on-rails sunspot facet

在这里使用其他问题的examples我有一个关于项目创建时间戳的日期范围分面搜索的基本设置。首先是一些代码:

/models/project.rb

class Project < ActiveRecord::Base
  searchable do
   time :created_at, :trie => true
   time :updated_at, :trie => true
  end
end

/controllers/projects_controller.rb

class ProjectsController < ApplicationController
  respond_to :html
  def index
    @search = Project.search do
      bod = Time.zone.now.beginning_of_day
      facet :created_at do
        row :past do
          with(:created_at).less_than bod - 1.day
        end
        row :today do
          with :created_at, bod
        end
      end
    end
    @projects = @search.results
    respond_with(@projects)
  end
end

/views/projects/index.html.erb

17:  <h3>Created At</h3>
18:  <ul>
19:  <% for row in @search.facet(:created_at).rows %>
20:    <li>
21:      <% if params[:created_at].blank? %>
22:        <%= link_to row.instance.name, :created_at => row.value %> (<%= row.count %>)
23:      <% else %>
24:        <strong><%= row.instance.name %></strong> (<%= link_to "X", :created_at => nil %>)
25:      <% end %>
26:    </li>
27:  <% end %>
28:  </ul>

当我加载http://localhost:3000/projects时,我从我的视图中第22行发生了以下错误:

undefined method `populate_instances' for #<Sunspot::Search::QueryFacet:0x00000103669d70>

我做错了什么?感谢。

0 个答案:

没有答案