简体   繁体   English

如何添加显示在Searchlogic中搜索到的内容的元素?

[英]How do I add an element that shows what was searched in Searchlogic?

I am using the gem Searchlogic for Rails. 我正在使用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 /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_controller.rb#index

@posts = @search.all(:order => "created_at DESC").paginate(
                 :page => params[:page], :per_page => 6)

app/controllers/posts_controller.rb 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 app / views / posts / index.html.erb

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM