Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VeNJob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tô Ngọc Ánh
VeNJob
Commits
9ca3a5e6
Commit
9ca3a5e6
authored
Aug 05, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create slug for location, industry
parent
f1070925
Pipeline
#813
failed with stages
in 0 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
71 additions
and
23 deletions
+71
-23
app/controllers/jobs_controller.rb
+4
-18
app/models/industry.rb
+13
-0
app/models/location.rb
+12
-0
app/views/industries/_industry.html.erb
+1
-1
app/views/locations/_location.html.erb
+1
-1
config/routes.rb
+1
-2
db/migrate/20200805034647_add_slug_to_industries.rb
+6
-0
db/migrate/20200805034659_add_slug_to_locations.rb
+6
-0
db/schema.rb
+5
-1
lib/common/convert_slug.rb
+22
-0
No files found.
app/controllers/jobs_controller.rb
View file @
9ca3a5e6
class
JobsController
<
ApplicationController
class
JobsController
<
ApplicationController
def
city_job
def
index
location
=
Location
.
find_by_id
(
params
[
:id
])
results
(
location
)
end
def
industry_job
industry
=
Industry
.
find_by_id
(
params
[
:id
])
results
(
industry
)
end
def
search
end
private
def
results
(
object
)
@keyword
=
object
.
try
(
:name
)
||
object
.
try
(
:city
)
@jobs
=
object
.
jobs
.
all
.
includes
(
:company
,
:locations
,
:industries
).
page
(
params
[
:page
])
@locations
=
Location
.
select
(
:id
,
:city
)
@locations
=
Location
.
select
(
:id
,
:city
)
@industries
=
Industry
.
select
(
:id
,
:name
)
@industries
=
Industry
.
select
(
:id
,
:name
)
object
=
params
[
:model
].
classify
.
constantize
.
find_by_slug
(
params
[
:slug
])
@keyword
=
object
.
try
(
:name
)
||
object
.
try
(
:city
)
@jobs
=
object
.
jobs
.
all
.
includes
(
:company
,
:locations
,
:industries
).
page
(
params
[
:page
])
render
'job_list'
render
'job_list'
end
end
end
end
app/models/industry.rb
View file @
9ca3a5e6
require
'./lib/common/convert_slug'
class
Industry
<
ApplicationRecord
class
Industry
<
ApplicationRecord
include
ConvertSlug
scope
:with_count_job
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
select
(
'industries.*, count(jobs.id) as job_count'
)
}
scope
:with_count_job
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
select
(
'industries.*, count(jobs.id) as job_count'
)
}
scope
:top_industries
,
->
(
number
)
{
with_count_job
.
order
(
Arel
.
sql
(
'job_count DESC'
)).
limit
(
number
)
}
scope
:top_industries
,
->
(
number
)
{
with_count_job
.
order
(
Arel
.
sql
(
'job_count DESC'
)).
limit
(
number
)
}
has_and_belongs_to_many
:jobs
has_and_belongs_to_many
:jobs
before_save
:add_slug
private
def
add_slug
self
.
slug
=
"
#{
self
.
id
}
-
#{
self
.
to_slug
(
self
.
name
)
}
"
end
end
end
app/models/location.rb
View file @
9ca3a5e6
require
'./lib/common/convert_slug.rb'
class
Location
<
ApplicationRecord
class
Location
<
ApplicationRecord
include
ConvertSlug
scope
:with_count_job
,
->
{
joins
(
:jobs
).
group
(
:location_id
).
select
(
'locations.*, count(jobs.id) as job_count'
)
}
scope
:with_count_job
,
->
{
joins
(
:jobs
).
group
(
:location_id
).
select
(
'locations.*, count(jobs.id) as job_count'
)
}
scope
:top_locations
,
->
(
number
)
{
with_count_job
.
order
(
Arel
.
sql
(
'job_count DESC'
)).
limit
(
number
)
}
scope
:top_locations
,
->
(
number
)
{
with_count_job
.
order
(
Arel
.
sql
(
'job_count DESC'
)).
limit
(
number
)
}
scope
:international
,
->
{
where
(
oversea:
true
)
}
scope
:international
,
->
{
where
(
oversea:
true
)
}
...
@@ -8,4 +12,12 @@ class Location < ApplicationRecord
...
@@ -8,4 +12,12 @@ class Location < ApplicationRecord
has_many
:locations_jobs
has_many
:locations_jobs
has_many
:jobs
,
through: :locations_jobs
has_many
:jobs
,
through: :locations_jobs
before_save
:add_slug
private
def
add_slug
self
.
slug
=
"
#{
self
.
id
}
-
#{
self
.
to_slug
(
self
.
city
)
}
"
end
end
end
app/views/industries/_industry.html.erb
View file @
9ca3a5e6
<div
class=
'col-4 my-2'
>
<div
class=
'col-4 my-2'
>
<div
class=
'card'
>
<div
class=
'card'
>
<%=
link_to
industry_jobs_path
(
industry
),
class:
'card-body text-decoration-none'
do
%>
<%=
link_to
jobs_path
(
model:
'industry'
,
slug:
industry
.
slug
),
class:
'card-body text-decoration-none'
do
%>
<h5
class=
'card-title font-weight-bold'
>
<%=
industry
.
name
%>
</h5>
<h5
class=
'card-title font-weight-bold'
>
<%=
industry
.
name
%>
</h5>
<p
class=
'card-text'
>
<%=
pluralize
(
industry
.
job_count
,
'Job'
)
%>
</p>
<p
class=
'card-text'
>
<%=
pluralize
(
industry
.
job_count
,
'Job'
)
%>
</p>
<%
end
%>
<%
end
%>
...
...
app/views/locations/_location.html.erb
View file @
9ca3a5e6
<div
class=
'col-4 my-2'
>
<div
class=
'col-4 my-2'
>
<div
class=
'card'
>
<div
class=
'card'
>
<%=
link_to
city_jobs_path
(
location
),
class:
'card-body text-decoration-none'
do
%>
<%=
link_to
jobs_path
(
model:
'location'
,
slug:
location
.
slug
),
class:
'card-body text-decoration-none'
do
%>
<h5
class=
'card-title font-weight-bold'
>
<%=
location
.
city
%>
</h5>
<h5
class=
'card-title font-weight-bold'
>
<%=
location
.
city
%>
</h5>
<p
class=
'card-text'
>
<%=
pluralize
(
location
.
job_count
,
'Job'
)
%>
</p>
<p
class=
'card-text'
>
<%=
pluralize
(
location
.
job_count
,
'Job'
)
%>
</p>
<%
end
%>
<%
end
%>
...
...
config/routes.rb
View file @
9ca3a5e6
...
@@ -2,7 +2,6 @@ Rails.application.routes.draw do
...
@@ -2,7 +2,6 @@ Rails.application.routes.draw do
root
to:
'home#index'
root
to:
'home#index'
get
'cities'
,
to:
'locations#index'
get
'cities'
,
to:
'locations#index'
get
'industries'
,
to:
'industries#index'
get
'industries'
,
to:
'industries#index'
get
'jobs/city/:id'
,
to:
'jobs#city_job'
,
as: :city_jobs
get
'jobs/:model/:slug'
,
to:
'jobs#index'
,
as: :jobs
get
'jobs/industry/:id'
,
to:
'jobs#industry_job'
,
as: :industry_jobs
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
end
db/migrate/20200805034647_add_slug_to_industries.rb
0 → 100644
View file @
9ca3a5e6
class
AddSlugToIndustries
<
ActiveRecord
::
Migration
[
5.2
]
def
change
add_column
:industries
,
:slug
,
:string
add_index
:industries
,
:slug
,
unique:
true
end
end
db/migrate/20200805034659_add_slug_to_locations.rb
0 → 100644
View file @
9ca3a5e6
class
AddSlugToLocations
<
ActiveRecord
::
Migration
[
5.2
]
def
change
add_column
:locations
,
:slug
,
:string
add_index
:locations
,
:slug
,
unique:
true
end
end
db/schema.rb
View file @
9ca3a5e6
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2020_0
7_20_075150
)
do
ActiveRecord
::
Schema
.
define
(
version:
2020_0
8_05_034659
)
do
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"user_id"
t
.
bigint
"user_id"
...
@@ -55,6 +55,8 @@ ActiveRecord::Schema.define(version: 2020_07_20_075150) do
...
@@ -55,6 +55,8 @@ ActiveRecord::Schema.define(version: 2020_07_20_075150) do
t
.
string
"name"
t
.
string
"name"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
string
"slug"
t
.
index
[
"slug"
],
name:
"index_industries_on_slug"
,
unique:
true
end
end
create_table
"industries_jobs"
,
id:
false
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
create_table
"industries_jobs"
,
id:
false
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
...
@@ -82,6 +84,8 @@ ActiveRecord::Schema.define(version: 2020_07_20_075150) do
...
@@ -82,6 +84,8 @@ ActiveRecord::Schema.define(version: 2020_07_20_075150) do
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
boolean
"oversea"
t
.
boolean
"oversea"
t
.
string
"slug"
t
.
index
[
"slug"
],
name:
"index_locations_on_slug"
,
unique:
true
end
end
create_table
"locations_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
create_table
"locations_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
...
...
lib/common/convert_slug.rb
0 → 100644
View file @
9ca3a5e6
module
ConvertSlug
def
to_slug
(
str
)
str
=
str
.
to_s
.
strip
.
downcase
accents
=
{
%w[à á ạ ả ã â ầ ấ ậ ẩ ẫ ă ằ ắ ặ ẳ ẵ]
=>
'a'
,
%w[è é ẹ ẻ ẽ ê ề ế ệ ể ễ]
=>
'e'
,
%w[ì í ị ỉ ĩ]
=>
'i'
,
%w[ò ó ọ ỏ õ ô ồ ố ộ ổ ỗ ơ ờ ớ ợ ở ỡ]
=>
'o'
,
%w[ù ú ụ ủ ũ ư ừ ứ ự ử ữ]
=>
'u'
,
%w[ỳ ý ỵ ỷ ỹ]
=>
'y'
,
%w[đ]
=>
'd'
}
accents
.
each
do
|
ac
,
rep
|
ac
.
each
do
|
s
|
str
=
str
.
tr
(
s
,
rep
)
end
end
str
.
parameterize
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment