I would like to show the search parameter of a search object. I using rails and sunspot.
Lets say I have this book application where store a bunch of books and whould like to search the book by them name and title.
The book model:
class Book < ActiveRecord::Base
validates_presence_of :title, :author_name
searchable do
text :title, :author_name
end
end
controller:
class BooksController < ApplictionController
def index
@search = Book.search do
fulltext params[:search]
end
@results = @search.results
end
end
view:
<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>
How can I show the search parameter, where is that object?
So it outputs:
Your search: Jeff Hawkins
Eggs and butter
Jeff Hawkins
Change your controller code to:
And then in your view you can just do: