[RAILS]: список результатов по адресу с помощью Ransack - PullRequest
0 голосов
/ 12 июня 2018

Я новичок в Ror, мне нужна помощь, чтобы отобразить мои продукты на моей странице индекса.Я использую Ransack Gem, чтобы отфильтровать свои активные результаты, но мне не удается отфильтровать их рядом с геокодированным адресом, если он напечатан в форме ..?У каждого товара есть адрес.Спасибо за вашу помощь!

Вот мой код: products / index.html.erb

<%= search_form_for @search do |f| %>
  <label>Type d'article:</label><br>
  <%= f.label :name_cont, 'article:' %>
  <%= f.search_field :name_cont %>

  <%= f.label :brand_cont, 'marque:' %>
  <%= f.search_field :brand_cont %>

  <%= f.label :size_cont, 'taille:' %>
  <%= f.search_field :size_cont %>

  <label>Prix:</label><br>
  <%= f.label :price_gteq, 'prix min:' %>
  <%= f.number_field :price_gteq %>

  <%= f.label :price_lteq, 'prix max:' %>
  <%= f.number_field :price_lteq %>

  <label>Adresse:</label>
  <%= f.text_field :address, placeholder: "Où est situé votre article ?", id:"user_input_autocomplete_address", class: "form-control" %>
  <input id="street_number" name="street_number" disabled type="hidden">
  <input id="route" name="route" disabled type="hidden">
  <input id="locality" name="locality" disabled type="hidden">
  <input id="country" name="country" disabled type="hidden">

<%= f.submit 'Lancer la recherche', class:'btn btn-info btn-sm' %>                   
<% end %>
...
  <script type="text/javascript"
    src="https://maps.googleapis.com/maps/api/js?libraries=places&key=#{ENV['GOOGLE_API_JAVASCRIPT_KEY']}"></script>

Products controller.rb

class ProductsController < ApplicationController
   before_action :set_product, only: %i[show edit update destroy]
   before_action :authenticate_user!, except: %i[show index slide]

def index
    @search = Product.ransack(params[:q])
    @products = @search.result.where(active: true).near(@address, 50)
  end

private
  def product_params
    params.require(:product).permit(:name, :description, :brand, :category, :color, :size, :state, :price, :address, :status, :active)
  end
end
...