views:

19

answers:

1

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)
A: 

app/controllers/posts_controller.rb

class PostsController < ApplicationController
  def index
    if params[:search]
      @search_term = params[:search][:title_like_or_body_like]
    end
    # ...
  end
end

app/views/posts/index.html.erb

<% if @search_term %>
  <h1>Search results for "<%= @search_term %>"</h1>
<% end %>
macek