我在盒子模型上有这条线
acts_as_ferret :fields => [ :model ]
当然,box table 有一个名为 model 的字段。
这是搜索操作或目录控制器
def search
@page_title = "Busqueda"
if params[:commit] == "Search" || params[:q]
@boxes = Box.find_with_ferret(params[:q].to_s.upcase)
unless @boxes.size > 0
flash.now[:notice] = "No boxess found matching your criteria"
end
这就是搜索视图,这是 _search_box.html.erb
<%= form_tag({:action => "search"}, {:method => "get"} do ) %>
<%= text_field_tag :q %>
<%= submit_tag "Buscar" %>
<% end %>
这是search.html.erb
<% render :partial => "search_box" %>
<% if @boxes %>
<p>Your search "<%= params[:q] %>" produced
<%= pluralize @boxes.size, "result" %>:</p>
<%= render(:partial => "boxes") %>
<% end %>
似乎正确,但搜索总是返回 0 个结果。