devyk

new_pages_controller.rb

Sep 5th, 2018
672
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: 1).limit(3)
  4.   end
  5.  
  6.   def search
  7.     session[:loc_search] = params[:search] if params[:search].present?
  8.     hotels = Hotel.where(active: 1)
  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.start_date IS NULL",
  18.           { start_date: start_date, end_date: end_date, status: 1 }
  19.         ).group('hotels.id')
  20.  
  21.  
  22.     end
  23.     @search = hotels.ransack(params[:q])
  24.     @hotels = @search.result
  25.     Rails.logger.info "=============="
  26.     Rails.logger.info @hotels.count
  27.   end
  28.  
  29. end
RAW Paste Data