devyk

PagesController

Aug 18th, 2018
708
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PagesController < ApplicationController
  2.   def home
  3.     @hotels = Hotel.where(active: true).limit(3)
  4.   end
  5.  
  6.   def search
  7.     session[:loc_search] = params[:search] if params[:search].present?
  8.     hotels = Hotel.where(active: true)
  9.     hotels = hotels.near(session[:loc_search], 5, order: 'distance') if session[:loc_search].present?
  10.  
  11.     if (params[:start_date].present? && params[:end_date].present?)
  12.       start_date = Date.parse(params[:start_date])
  13.       end_date = Date.parse(params[:end_date])
  14.  
  15.       hotels = hotels.left_outer_joins(rooms: [:reservations, :calendars]).where.not(
  16.           "(((reservations.start_date BETWEEN :start_date AND :end_date)
  17.         OR (reservations.end_date BETWEEN :start_date AND :end_date)
  18.         OR (reservations.start_date < :start_date AND :end_date < reservations.end_date))
  19.         AND reservations.status = :status)
  20.         OR (calendars.status = :status AND calendars.day BETWEEN :start_date AND :end_date)",
  21.           { start_date: start_date, end_date: end_date, status: 1 }
  22.         )
  23.  
  24.     end
  25.     @search = hotels.ransack(params[:q])
  26.     @hotels = @search.result
  27.     Rails.logger.info "=============="
  28.     Rails.logger.info @hotels.count
  29.   end
  30.  
  31. end
RAW Paste Data