我正在使用gem Searchlogic for Rails。一切都运行得很好。我剩下的唯一问题是如何在查询后显示一个元素,如下所示:
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 %>posts_controller.rb#index
@posts = @search.all(:order => "created_at DESC").paginate(
:page => params[:page], :per_page => 6)发布于 2010-10-08 13:50:48
应用程序/控制器/posts_CONTRONTER.rb
class PostsController < ApplicationController
def index
if params[:search]
@search_term = params[:search][:title_like_or_body_like]
end
# ...
end
endapp/views/post/index.html.erb
<% if @search_term %>
<h1>Search results for "<%= @search_term %>"</h1>
<% end %>https://stackoverflow.com/questions/3874060
复制相似问题