【发布时间】:2021-06-14 10:09:43
【问题描述】:
我想通过她的预订检查我的优惠的可用性,
我试过这个范围:
我的模特:
scope :booking_available, -> (arrival_date, departure_date) {
joins(:bookings).where.not('bookings.arrival_date <= ? AND bookings.departure_date >= ? AND bookings.status != ?', arrival_date, departure_date, 0)
}
但我的搜索结果中的所有优惠都与检查的预订数量重复,
我尝试在范围末尾添加.distinct,但是当我使用其他搜索参数时,我收到错误PG::UndefinedFunction: ERROR: could not identify an equality operator for type json,类似于this error
我想知道我的可用性参数如何与其他搜索参数一起使用?
我的控制器:
if offer_params[:arrival_date].present? && offer_params[:departure_date].present?
@offers = @offers.booking_available(offer_params[:arrival_date], offer_params[:departure_date])
end
@offers = @offers
.page(params[:page])
.per(60)
respond_to do |format|
format.json { render template: 'offers/v2/search', status: :ok }
end
在我看来我如何呈现优惠:
json[:offers] = @offers.map do |offer|
end
【问题讨论】:
-
不是很清楚你真正的问题是什么。是
how my availability param can work with other search params ?还是I tried to add .distinct at the end of the scope but when i use other search params i got error? -
我的问题是
how my availability param can work with other search params ? -
您能举例说明您的搜索参数是什么意思吗?
标签: ruby-on-rails ruby postgresql