我的问题是如何在多输入搜索栏中使用多个过滤器过滤我的公告?
我想仅仅注明尊重我的条件的公告。
现在我只搜索地理定位和参考文献。
信息:
Annoucements_Controller.rb
def index
if params[:search]
@annoucements = Annoucement.all if params[:search][:search_by_city] == "" && params[:search][:search_by_reference] == ""
@annoucements = Annoucement.near(params[:search][:search_by_city], params[:search][:distance], units: :km) if params[:search][:search_by_city] != ""
@annoucements = Annoucement.search_by_city_and_reference(params[:search][:search_by_reference]) if params[:search][:search_by_reference] != ""
else
@annoucements = Annoucement.all
end
end
home.html.erb
<%= simple_form_for :search, url: annoucements_path, method: :get do |form|%>
<%= form.input :search_by_status,label: false , collection: ['A vendre', 'A louer'], selected: "A vendre"%>
<%= form.input :search_by_city, as: :string, label: false , placeholder: 'Ville'%>
<%= form.input :search_by_reference, as: :string, label: false , placeholder: 'Reference'%>
<%= form.input :distance, as: :hidden, input_html: {value: 10}%>
<%= form.submit "Rechercher", class: 'btn btn-primary' %>
<% end %>
annoucement.rb
geocoded_by :address
after_validation :geocode, if: :address_changed?
include PgSearch
pg_search_scope :search_by_city_and_reference, against: {:city => 'A', :reference => 'B'}
我的目标是过滤此表单中的所有数据: 的 index.html.erb
<%= simple_form_for :search, url: annoucements_path, method: :get do |form|%>
<%= form.input :search_by_status,label: false , collection: ['A vendre', 'A louer'], selected: "Achat"%>
<%= form.input :search_by_city, as: :string, label: false , placeholder: 'Ville'%>
<%= form.input :search_by_reference, as: :string, label: false , placeholder: 'Reference'%>
<%= form.input :distance, label: "Périmètre de recherche (en Km)", input_html: {value: 10}, collection: 1..50%>
<%= form.input :price, as: :integer, label: false , placeholder: 'Prix'%>
<%= form.input :number_of_bedroom, as: :integer, label: "Nombre de chambre", placeholder: 'Nombre de chambre'%>
<%= form.input :number_of_bathroom, as: :integer, label: 'Nombre de salle de bain',placeholder: 'Nombre de salle de bain'%>
<%= form.input :size, label: 'Taille du bien (m2)', as: :integer, placeholder: 'Taille du bien (m2)'%>
<%= form.input :field_size, as: :integer, label: 'Taille de terrain (m2)', placeholder: 'Taille de terrain (m2)'%>
<%= form.input :balcony, as: :boolean, placeholder: 'Balcon'%>
<%= form.input :garage, as: :boolean, placeholder: 'Garage'%>
<%= form.input :furnished, as: :boolean, placeholder: 'Meublé'%>
<%= form.submit "Rechercher", class: 'btn btn-primary' %>
<%end%>
谢谢你, 再见