I am using the gem Searchlogic for Rails. Everything is working great. The only question I have left is how to have an element display, after the query, that says something like:
Search Results for "whatever"
I can't find anything in the docs. Anyone have suggestions? Here is my code:
/posts/index.html.erb
<% form_for @search do |f| %>
<%= f.text_field (:title_like_or_body_like, :class => "search-field") %>
<%= f.submit "Search", :class => "search-field-button" %>
<% end %>
posts_controller.rb#index
@posts = @search.all(:order => "created_at DESC").paginate(
:page => params[:page], :per_page => 6)
class PostsController < ApplicationController
def index
if params[:search]
@search_term = params[:search][:title_like_or_body_like]
end
# ...
end
end
<% if @search_term %>
<h1>Search results for "<%= @search_term %>"</h1>
<% end %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.