Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PagesController < ApplicationController
- def home
- @hotels = Hotel.where(active: 1).limit(3)
- end
- def search
- session[:loc_search] = params[:search] if params[:search].present?
- hotels = Hotel.where(active: 1)
- hotels = hotels.near(session[:loc_search], 5, order: 'distance') if session[:loc_search].present?
- if (params[:start_date].present? && params[:end_date].present?)
- start_date = Date.parse(params[:start_date])
- end_date = Date.parse(params[:end_date])
- hotels = hotels.left_outer_joins(rooms: [:reservations, :calendars]).where.not(
- "(reservations.start_date BETWEEN :start_date AND :end_date)
- OR reservations.start_date IS NULL",
- { start_date: start_date, end_date: end_date, status: 1 }
- ).group('hotels.id')
- end
- @search = hotels.ransack(params[:q])
- @hotels = @search.result
- Rails.logger.info "=============="
- Rails.logger.info @hotels.count
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement