0

我正在为 Rails 使用 gem Searchlogic。一切都很好。我剩下的唯一问题是如何在查询后显示一个元素,显示如下:

Search Results for "whatever"

我在文档中找不到任何内容。有人有建议吗?这是我的代码:

/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 %>

post_controller.rb#index

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

1 回答 1

0

应用程序/控制器/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 %>
于 2010-10-08T05:50:48.150 回答