Commit eedcd09e by Thanh Hung Pham

Search complete

parent 60fdeba5
......@@ -10,6 +10,6 @@ class AdminsController < ApplicationController
@from_date_default = Date.new(params[:from_date]['(1i)'].to_i, params[:from_date]['(2i)'].to_i, params[:from_date]['(3i)'].to_i) if params[:from_date].present?
@to_date_default = Date.new(params[:to_date]['(1i)'].to_i, params[:to_date]['(2i)'].to_i, params[:to_date]['(3i)'].to_i) if params[:to_date].present?
@applied_jobs = Apply.applied_at_between(@from_date_default, @to_date_default).page params[:page]
@applied_jobs = Apply.search_email(@email).search_city(@city_id).search_city(@category_id).applied_at_between(@from_date_default, @to_date_default).page params[:page]
end
end
......@@ -4,5 +4,8 @@ class Apply < ApplicationRecord
paginates_per 20
scope :applied_at_between, ->(from_date, to_date) { where('applied_at >= ? AND applied_at <= ?', from_date, to_date) }
scope :applied_at_between, ->(from_date, to_date) { where('DATE(applied_at) >= ? AND DATE(applied_at) <= ?', from_date, to_date) }
scope :search_email, ->(email) { joins(:user).where('? IS NULL OR users.email = ?', email, email) }
scope :search_city, ->(city_id) { joins(:job).where('? IS NULL OR jobs.city_id = ?', city_id, city_id) }
scope :search_category, ->(category_id) { joins(job: [:job_category]).where('? IS NULL OR job_categories.category_id = ?', category_id, category_id) }
end
class User < ApplicationRecord
attr_accessor :skip_password_validation, :skip_fullname_validation, :upload
has_many :applies
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment