当我搜索模型时,太阳黑子不会返回任何内容:
的routes.rb
get 'product/:q' => 'store#product'
store_controller.rb
if (!!(params[:q] =~ /^[-+]?[0-9]+$/)) == false #if no number
@note = "hello"
@search = Product.search do
fulltext params[:q]
@note2 = "hello2"
end
@food_input = @search.results
else #if number
@food_input = params[:q]
end
product.rb
class Product < ActiveRecord::Base
searchable do
text :name
end
end
product.html.erb
<% if @search.present? %>
<% @food_input.each do |product| %>
<%= link_to product.name, product.barcode_number %>
<% end %>
<p>is number?: <%= !!(params[:q] =~ /^[-+]?[0-9]+$/) %></p>
<p>param q: <%= params[:q] %></p>
<p>empty?: <%= @food_input.empty? %></p>
<p>note: <%= @note %></p>
<p>note2: <%= @note2 %></p>
搜索Kat时的浏览器输出:
is number?: false
param q: Kat
empty?: true
note: hello
note2:
如你所见,没有结果,没有@ note2变量。有谁知道为什么?
答案 0 :(得分:1)
从我的评论:rake sunspot:reindex
,现在您可以将问题标记为已回答;)