Skip to content

Commit e5fe779

Browse files
committed
Add filtering by job type
1 parent 441bc00 commit e5fe779

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

app/controllers/jobs_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class JobsController < ApplicationController
44
# GET /jobs
55
# GET /jobs.json
66
def index
7+
@jobs = @jobs.where(job_type: params[:job_type]) if params[:job_type]
78
@jobs = @jobs.page(params[:page])
89

910
respond_to do |format|

app/helpers/jobs_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ def render_job_badge(job)
1212
else
1313
'badge-default'
1414
end
15-
content_tag :div, job.job_type.humanize, class: "badge #{badge_class}"
15+
link_to job.job_type.humanize, type_jobs_path(job_type: job.job_type), class: "badge #{badge_class}"
1616
end
1717
end

app/views/jobs/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<p id="notice"><%= notice %></p>
66
<%= link_to 'New Job', new_job_path, class: 'btn btn-primary float-right' if can? :create, Job %>
77

8-
<h1>Jobs</h1>
8+
<h1><%= params[:job_type].humanize if params[:job_type] %> Jobs</h1>
99
<%= render 'table', jobs: @jobs %>
1010

1111
<br>

config/routes.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Rails.application.routes.draw do
2-
resources :jobs
2+
resources :jobs do
3+
collection do
4+
get 'type/:job_type', to: 'jobs#index', as: :type
5+
end
6+
end
37
resources :employers
48
resources :tags, only: [:index, :show]
59
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }

0 commit comments

Comments
 (0)