我在盒子模型上有这一行
acts_as_ferret :fields => [ :model ]
当然,box表有一个名为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结果。