Я работаю над приложением, я фактически реализую фильтр в своем пользовательском индексе для поиска некоторых пользователей по: языку, городу и доступности (дате). Фильтр по языку и городу работает отлично, но не по дате.
index.html.erb :
<div>
Date de départ :
<%= f.text_field :with_start_time_gte, 'data-provide' => 'datepicker' %>
</div>
<%= f.submit 'Rechercher' %>
Я создаю модель Availability с параметрами (:name, :start_time, :end_time, :user_id). Мне нужно, чтобы фильтр выполнял поиск между датой между start_time и end_time доступности и возвращал доступных пользователей.
users_controller.rb :
def index
@filterrific = initialize_filterrific(
User,
params[:filterrific]
#persistence_id: 'shared_key',
#default_filter_params: {},
#available_filters: [],
) or return
@users = @filterrific.find.page(params[:page])
# Respond to html for initial page load and to js for AJAX filter updates.
respond_to do |format|
format.html
format.js
end
rescue ActiveRecord::RecordNotFound => e
# There is an issue with the persisted param_set. Reset it.
puts "Had to reset filterrific params: #{ e.message }"
redirect_to(reset_filterrific_url(format: :html)) and return
end
пользователь.рб :
filterrific(
default_filter_params: {},
available_filters: [
:with_mother_tongue,
:with_locality,
:with_start_time_gte])
scope :with_mother_tongue, -> (search_string) {
where("users.mother_tongue LIKE ?", (search_string.to_s.gsub('*', '%') + '%').gsub(/%+/, '%'))
}
scope :with_locality, -> (search_string) {
where("users.locality LIKE ?", (search_string.to_s.gsub('*', '%') + '%').gsub(/%+/, '%'))
}
scope :with_start_time_gte, lambda { |ref_date|
where('users.availabilities.start_time >= ?', ref_date)
}
Я думаю, что проблема в том, чтобы взять start_time из доступности пользователя... Но не знаю, как это сделать... Заранее спасибо за вашу помощь!