ruby-on-rails - 如何将我的复选框过滤器与我的搜索表单相关联?
问题描述
我有一个搜索帖子的搜索表单,但我希望用户能够根据各种属性过滤这些搜索。如何将复选框过滤器链接到搜索?我正在使用太阳黑子宝石过滤帖子。
这是post.rb
class Post < ActiveRecord::Base
belongs_to :user
searchable do
text :details
text :title
end
end
这是帖子文件夹中的 show.html.erb
<div class = "container">
<% @posts.each do |x| %>
<div class="fb" id="download">
<div class="post">
<div class="top">
<div class="name">
<strong><a href="#"><span class="text-name"><%= x.title %></span></a></strong>
</div>
</div>
<span class="text-message"><%= x.details %></span><br><br>
</div>
</div>
<% end %>
</div>
这是我的帖子控制器中的显示功能
def show
@search = Post.search do
fulltext params[:search]
end
@posts = @search.results
end
这是我的 application.html.erb 中的搜索表单
<% if current_user.profile %>
<li><%= form_tag user_post_path(user_id: current_user.id), :method => :get do %>
<p>
<%= text_field_tag :search, params[:search], autocomplete: "off", placeholder: "Try \"Tennis\"" %>
<button type="submit"><i class="fa fa-search"></i>
<% end %></li>
<li><%= link_to "Create Post", new_user_post_path(user_id: current_user.id), class: "linkfocus"%></li>
<li><%= link_to "Profile", user_path(id:current_user.id), class: "linkfocus"%></li>
<% else %>
解决方案
推荐阅读
- python - Python smtplib 发送的附加文件名中的无名
- c - main 和 __libc_start_main 之间的区别
- neo4j - Neo4J 查找节点之间关系的数量(SIZE)
- flutter - Flutter Navigation 参数不会在更改时更新?
- javascript - Cannot understand behaviour of promises in javascript
- regex - How do I extract text from awk results?
- r - 连接 R 中的三个表,每个表都有不同的键
- odata - 使用 Lucene 查询语法的 Azure 搜索查询是否可以有一个带有 geo.distance 函数和另一个过滤条件的过滤器?
- java - BigDecimal 除数不四舍五入
- javascript - AJAX code returns error of "Column cannot be null" for PHP Session variable