Skip to content

Commit 5237313

Browse files
author
Dave Newman
committed
Implement job filtering
1 parent 01669e0 commit 5237313

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

app/controllers/jobs_controller.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ def index
66
params[:show_contract] ||= true
77
# raise params.inspect
88

9+
roles = []
10+
roles.push(Job::FULLTIME) if params[:show_fulltime] == 'true'
11+
roles.push(Job::PARTTIME) if params[:show_parttime] == 'true'
12+
roles.push(Job::CONTRACT) if params[:show_contract] == 'true'
913
@jobs = Job.active.order(created_at: :desc)
1014

11-
# if params[:show_fulltime]
12-
#
13-
# where("role_type != ?", JOB::FULLTIME)
14-
# end
15-
16-
if !params[:show_contract]
17-
18-
end
15+
@jobs = @jobs.where('jobs.role_type in (?)', roles)
16+
@jobs = @jobs.where(location: 'Remote') if params[:show_remote] == 'true'
17+
@jobs = @jobs.where('jobs.location ilike :q or jobs.title ilike :q or jobs.company ilike :q', q: "%#{params[:q]}%") unless params[:q].blank?
1918

2019
if params[:posted]
2120
@jobs = @jobs.where.not(id: params[:posted])

app/views/jobs/index.html.haml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88
=form_tag jobs_path, method: :get do
99
= text_field_tag :q, params[:q], placeholder: 'Search great jobs by Location, Title, or Company', class: 'field col-6'
1010
.col-1.inline.ml1
11-
= check_box_tag :show_fulltime, true, params[:show_fulltime]
11+
= hidden_field_tag :show_fulltime, false, id: nil
12+
= check_box_tag :show_fulltime, true, params[:show_fulltime] == 'true'
1213
= label_tag :show_fulltime, 'Full Time'
13-
= check_box_tag :show_contract, true, params[:show_contract]
14+
15+
= hidden_field_tag :show_parttime, false, id: nil
16+
= check_box_tag :show_parttime, true, params[:show_parttime] == 'true'
17+
= label_tag :show_parttime, 'Part Time'
18+
19+
= hidden_field_tag :show_contract, false, id: nil
20+
= check_box_tag :show_contract, true, params[:show_contract] == 'true'
1421
= label_tag :show_contract, 'Contracting'
15-
= check_box_tag :show_remote, true, params[:show_remote]
16-
= label_tag :show_remote, 'Remote'
22+
23+
= hidden_field_tag :show_remote, false, id: nil
24+
= check_box_tag :show_remote, true, params[:show_remote] == 'true'
25+
= label_tag :show_remote, 'Remote Only'
1726
.col-1.inline.ml1
1827
%button.btn.bg-purple.white.rounded{type: 'submit'}= icon('search')
1928
.col.sm-col-1

0 commit comments

Comments
 (0)