Рельсы: 5.1.4
Я пытаюсь выполнить поиск по :immo_type и/или :address
class SearchesController < ApplicationController
def home
@search = Purchase.find(params[:immo_type])
@purchases = Purchase.where("immo_type ILIKE ?", "%#{@search}%")
end
def index
@purchases = Purchase.all
@spurchases = Purchase.search_by_immo_type_and_address('@search')
end
конец
Из представления я использовал simple_form_for. Я не знаю, как посмотреть, как получить доступ к содержимому params[:immo_type]. Когда я использовал рельсы, у меня было это сообщение
Не удалось найти покупку с 'id'=
Я могу видеть все свои покупки с помощью Purchase.all
<%= simple_form_for :immo_type, url: searches_url, method: :get do |f| %>
<%= f.hidden_field :immo_type, params[:immo_type] %>
<%= f.input :address, placeholder: 'Town', label: "Where" %>
<%= f.input :immo_type, placeholder: 'flat, house', label: "Flat or house" %>
<%= f.button :submit, "Rechercher", class: "btn btn-danger" %>
<% end %>
Здесь мои модели
class Purchase < ApplicationRecord
include PgSearch
pg_search_scope :search_by_immo_type_and_address, against: [:immo_type, :address]
belongs_to :user
has_many :users, :through => :searches
end
class Search < ApplicationRecord
belongs_to :user
belongs_to :leasing
belongs_to :purchase
end
Я хотел бы выполнить поиск с моего home.html.erb (корневые страницы) и отобразить результат на моем index.html.erb
SearchesIndex
<ul>
<% @purchases.each do |purchase| %>
<li><%= link_to purchase.address %></li>
maison ou appartement : <%= purchase.immo_type %><br>
prix : entre <%= purchase.price_min %> et <%= purchase.price_max %><br>
<% end %>
</ul>