我想显示搜索对象的搜索参数。我使用铁轨和太阳黑子。
假设我有这个书应用程序,其中存储了一堆书,并且想按它们的名称和标题搜索书。
图书型号:
class Book < ActiveRecord::Base
validates_presence_of :title, :author_name
searchable do
text :title, :author_name
end
end
控制器:
class BooksController < ApplictionController
def index
@search = Book.search do
fulltext params[:search]
end
@results = @search.results
end
end
看法:
<div>
<h1>You search: </h1>
<% for result in @results %>
<li>
<h3><%= link_to result.title, result %></h3>
<p><%= result.author_name %></p>
</li>
<% end %>
</div>
如何显示搜索参数,该对象在哪里?
所以它输出:
Your search: Jeff Hawkins
Eggs and butter
Jeff Hawkins