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
0
Merge Requests
0
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
Huỳnh Thiên Phước
venjob
Commits
df3204f9
Commit
df3204f9
authored
Aug 11, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix code mentor's comment
parent
d3ddaa64
Pipeline
#877
canceled with stages
in 0 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
63 additions
and
47 deletions
+63
-47
app/controllers/jobs_controller.rb
+16
-6
app/helpers/convert.rb
+0
-5
app/models/application_record.rb
+4
-0
app/models/city.rb
+5
-3
app/models/company.rb
+5
-3
app/models/industry.rb
+5
-3
app/models/job.rb
+9
-6
app/views/jobs/index.html.erb
+0
-3
app/views/jobs/show.html.erb
+17
-17
config/routes.rb
+2
-1
No files found.
app/controllers/jobs_controller.rb
View file @
df3204f9
class
JobsController
<
ApplicationController
class
JobsController
<
ApplicationController
before_action
:set_job
,
only:
[
:show
]
before_action
:use_variables
before_action
:use_variables
def
index
def
index
@jobs_list
=
Job
.
all
_job
.
page
(
params
[
:page
]).
per
(
20
)
@jobs_list
=
Job
.
all
.
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
end
end
def
city_jobs
def
city_jobs
@city
=
City
.
find_by
(
converted_name:
params
[
:converted_name
])
@city
=
City
.
find_by
(
converted_name:
params
[
:converted_name
])
@jobs_list
=
@city
.
jobs
.
all_job
.
page
(
params
[
:page
]).
per
(
20
)
@jobs_list
=
@city
.
jobs
.
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
@result_for_job
=
@city
.
jobs
.
count
@result_for_job
=
@city
.
jobs
.
count
end
end
def
industry_jobs
def
industry_jobs
@industry
=
Industry
.
find_by
(
converted_name:
params
[
:converted_name
])
@industry
=
Industry
.
find_by
(
converted_name:
params
[
:converted_name
])
@jobs_list
=
@industry
.
jobs
.
all_job
.
page
(
params
[
:page
]).
per
(
20
)
@jobs_list
=
@industry
.
jobs
.
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
@result_for_job
=
@industry
.
jobs
.
count
@result_for_job
=
@industry
.
jobs
.
count
end
end
def
company_jobs
def
company_jobs
@company
=
Company
.
find_by
(
converted_name:
params
[
:converted_name
])
@company
=
Company
.
find_by
(
converted_name:
params
[
:converted_name
])
@jobs_list
=
@company
.
jobs
.
all_job
.
page
(
params
[
:page
]).
per
(
20
)
@jobs_list
=
@company
.
jobs
.
page
(
params
[
:page
]).
per
(
Job
::
LIMIT_PAGE
)
@result_for_job
=
@company
.
jobs
.
count
@result_for_job
=
@company
.
jobs
.
count
redirect_to
jobs_path
unless
@company
end
end
def
detail
def
show
@job_details
=
Job
.
find
(
params
[
:id
])
redirect_to
jobs_path
unless
@job
end
private
def
set_job
@job
||=
Job
.
find_by
(
params
[
:id
])
end
end
def
use_variables
def
use_variables
...
@@ -33,3 +42,4 @@ class JobsController < ApplicationController
...
@@ -33,3 +42,4 @@ class JobsController < ApplicationController
@total_job
=
Job
.
count
@total_job
=
Job
.
count
end
end
end
end
app/helpers/convert.rb
deleted
100644 → 0
View file @
d3ddaa64
module
ConvertsHelper
def
to_convert
(
str
)
str
.
mb_chars
.
normalize
(
:kd
).
gsub
(
/[Đđ]/
,
'd'
).
gsub
(
/[^\x00-\x7F]/
,
''
).
gsub
(
/[\W+]/
,
' '
).
downcase
.
to_s
.
split
(
' '
).
join
(
'-'
)
end
end
app/models/application_record.rb
View file @
df3204f9
class
ApplicationRecord
<
ActiveRecord
::
Base
class
ApplicationRecord
<
ActiveRecord
::
Base
self
.
abstract_class
=
true
self
.
abstract_class
=
true
def
convert_attribute
self
.
converted_name
=
normalize_attribute
.
mb_chars
.
normalize
(
:kd
).
gsub
(
/[Đđ]/
,
'd'
).
gsub
(
/[^\x00-\x7F]/
,
''
).
gsub
(
/[\W+]/
,
' '
).
downcase
.
to_s
.
split
(
' '
).
join
(
'-'
)
end
end
end
app/models/city.rb
View file @
df3204f9
class
City
<
ApplicationRecord
class
City
<
ApplicationRecord
before_save
:convert_
city
before_save
:convert_
attribute
has_many
:city_jobs
has_many
:city_jobs
has_many
:jobs
,
through: :city_jobs
has_many
:jobs
,
through: :city_jobs
...
@@ -9,7 +9,9 @@ class City < ApplicationRecord
...
@@ -9,7 +9,9 @@ class City < ApplicationRecord
scope
:top_city
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
}
scope
:top_city
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
}
scope
:location
,
->
(
number
)
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
where
(
location:
number
)
}
scope
:location
,
->
(
number
)
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
where
(
location:
number
)
}
def
convert_city
private
self
.
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
#{
rand
(
10000
)
}
"
)
def
normalize_attribute
name
end
end
end
end
app/models/company.rb
View file @
df3204f9
class
Company
<
ApplicationRecord
class
Company
<
ApplicationRecord
before_save
:convert_
company
before_save
:convert_
attribute
has_many
:jobs
has_many
:jobs
def
convert_company
private
self
.
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
#{
rand
(
10000
)
}
"
)
def
normalize_attribute
name
end
end
end
end
app/models/industry.rb
View file @
df3204f9
class
Industry
<
ApplicationRecord
class
Industry
<
ApplicationRecord
before_save
:convert_
industry
before_save
:convert_
attribute
has_many
:industry_jobs
has_many
:industry_jobs
has_many
:jobs
,
through: :industry_jobs
has_many
:jobs
,
through: :industry_jobs
scope
:top_industry
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
}
scope
:top_industry
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
}
scope
:all_industry
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
order
(
'count(job_id) DESC'
)
}
scope
:all_industry
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
order
(
'count(job_id) DESC'
)
}
def
convert_industry
private
self
.
converted_name
=
Convert
.
to_convert
(
"
#{
name
}
#{
rand
(
10000
)
}
"
)
def
normalize_attribute
name
end
end
end
end
app/models/job.rb
View file @
df3204f9
class
Job
<
ApplicationRecord
class
Job
<
ApplicationRecord
before_save
:convert_
job
before_save
:convert_
attribute
belongs_to
:company
belongs_to
:company
has_many
:city_jobs
has_many
:city_jobs
has_many
:cities
,
through: :city_jobs
has_many
:cities
,
through: :city_jobs
...
@@ -16,15 +16,18 @@ class Job < ApplicationRecord
...
@@ -16,15 +16,18 @@ class Job < ApplicationRecord
has_many
:histories
has_many
:histories
has_many
:users
,
through: :histories
has_many
:users
,
through: :histories
scope
:limit_job
,
->
{
includes
(
:cities
,
:company
).
order
(
created_at: :desc
).
limit
(
5
)
}
LIMIT_PAGE
=
20
scope
:all_job
,
->
{
limit
(
20
).
order
(
created_at: :desc
)
}
def
convert_job
scope
:limit_job
,
->
{
includes
(
:cities
,
:company
).
order
(
created_at: :desc
).
limit
(
5
)
}
converted_name
=
Convert
.
to_convert
(
"
#{
title
}
#{
rand
(
10000
)
}
"
)
end
def
company_name
def
company_name
company
&
.
name
company
&
.
name
end
end
private
def
normalize_attribute
title
end
end
end
app/views/jobs/index.html.erb
View file @
df3204f9
...
@@ -6,9 +6,6 @@
...
@@ -6,9 +6,6 @@
<div
class=
"row total-jobs"
>
<div
class=
"row total-jobs"
>
<div
class=
"col-4"
><strong>
Total:
<%=
@total_job
%>
jobs
</strong></div>
<div
class=
"col-4"
><strong>
Total:
<%=
@total_job
%>
jobs
</strong></div>
</div>
</div>
<div
class=
"paginate-jobs"
>
<%=
paginate
@jobs_list
,
left:
3
,
right:
3
%>
</div>
<%=
render
"jobs/pagination"
%>
<%=
render
"jobs/pagination"
%>
<div
class=
"job-list"
>
<div
class=
"job-list"
>
<%=
render
partial:
"job"
,
collection:
@jobs_list
,
as: :job
%>
<%=
render
partial:
"job"
,
collection:
@jobs_list
,
as: :job
%>
...
...
app/views/jobs/
detail
.html.erb
→
app/views/jobs/
show
.html.erb
View file @
df3204f9
...
@@ -2,21 +2,21 @@
...
@@ -2,21 +2,21 @@
<div
class=
"details-banner"
>
<div
class=
"details-banner"
>
<div
class=
"job-details-banner"
>
<div
class=
"job-details-banner"
>
<div
class=
"job-info"
>
<div
class=
"job-info"
>
<div><strong>
<%=
@job
_details
.
title
%>
</strong></div>
<div><strong>
<%=
@job
.
title
%>
</strong></div>
<div>
<div>
<%=
link_to
@job
_details
.
company_name
,
company_jobs_path
(
converted_name:
@job_details
.
company
.
converted_name
),
class:
'company'
%>
<%=
link_to
@job
.
company_name
,
company_jobs_path
(
converted_name:
@job
.
company
.
converted_name
),
class:
'company'
%>
</div>
</div>
<div
class=
"breadcrumb"
>
<div
class=
"breadcrumb"
>
<%=
link_to
"TOP"
,
root_path
%>
 
/
 
<%=
link_to
"TOP"
,
root_path
%>
 
/
 
<div>
<div>
<%
@job
_details
.
cities
.
each
do
|
city
|
%>
<%
@job
.
cities
.
each
do
|
city
|
%>
<%=
link_to
city
.
name
,
city_jobs_path
(
converted_name:
city
.
converted_name
)
,
class:
'location'
%>
<%=
link_to
city
.
name
,
city_jobs_path
(
converted_name:
city
.
converted_name
)
,
class:
'location'
%>
<%
end
%>
 
/
 
<%
end
%>
/
 
</div>
</div>
<%
@job
_details
.
industries
.
each
do
|
industry
|
%>
<%
@job
.
industries
.
each
do
|
industry
|
%>
<%=
link_to
industry
.
name
,
industry_jobs_path
(
converted_name:
industry
.
converted_name
),
class:
'industry'
%>
<%=
link_to
industry
.
name
,
industry_jobs_path
(
converted_name:
industry
.
converted_name
),
class:
'industry'
%>
<%
end
%>
 
/
 
<%
end
%>
/
 
<%=
@job
_details
.
title
.
truncate_words
(
5
)
%>
<%=
@job
.
title
.
truncate_words
(
5
)
%>
</div>
</div>
<%=
link_to
'#'
do
%>
<%=
link_to
'#'
do
%>
<div
class=
"apply-job"
>
<div
class=
"apply-job"
>
...
@@ -28,42 +28,42 @@
...
@@ -28,42 +28,42 @@
</div>
</div>
<div
class=
"details"
>
<div
class=
"details"
>
<div
class=
"job-infomation"
>
<div
class=
"job-infomation"
>
<h1>
<%=
@job
_details
.
title
%>
</h1>
<h1>
<%=
@job
.
title
%>
</h1>
<div
class=
"row info border border-dark"
>
<div
class=
"row info border border-dark"
>
<div
class=
"col-6"
>
<div
class=
"col-6"
>
<div
class=
"city"
>
<div
class=
"city"
>
<strong>
Location:
</strong>
<strong>
Location:
</strong>
<%
@job
_details
.
cities
.
each
do
|
city
|
%>
<%
@job
.
cities
.
each
do
|
city
|
%>
<%=
link_to
city
.
name
,
city_jobs_path
(
converted_name:
city
.
converted_name
),
class:
'location'
%>
<%=
link_to
city
.
name
,
city_jobs_path
(
converted_name:
city
.
converted_name
),
class:
'location'
%>
<%
end
%>
<%
end
%>
</div>
</div>
<div
class=
"created-day"
>
<div
class=
"created-day"
>
<strong>
Created at
</strong>
:
<%=
@job
_details
.
created_at
.
strftime
(
'%d/%m/%Y'
)
%>
<strong>
Created at
</strong>
:
<%=
@job
.
created_at
.
strftime
(
'%d/%m/%Y'
)
%>
</div>
</div>
<div
class=
"industry"
>
<div
class=
"industry"
>
<strong>
Industry:
</strong>
<%=
@job
_details
.
industries
.
map
(
&
:name
).
join
(
', '
)
%>
<strong>
Industry:
</strong>
<%=
@job
.
industries
.
map
(
&
:name
).
join
(
', '
)
%>
</div>
</div>
</div>
</div>
<div
class=
"col-6"
>
<div
class=
"col-6"
>
<div
class=
"salary-detail"
>
<div
class=
"salary-detail"
>
<strong>
Salary:
</strong>
<%=
@job
_details
.
salary
%>
<strong>
Salary:
</strong>
<%=
@job
.
salary
%>
</div>
</div>
<%
if
@job
_details
.
experience
.
present?
%>
<%
if
@job
.
experience
.
present?
%>
<div
class=
"experience"
>
<div
class=
"experience"
>
<strong>
Experience:
</strong>
<%=
@job
_details
.
experience
%>
<strong>
Experience:
</strong>
<%=
@job
.
experience
%>
</div>
</div>
<%
end
%>
<%
end
%>
<div
class=
"level"
>
<div
class=
"level"
>
<strong>
Level:
</strong>
<%=
@job
_details
.
level
%>
<strong>
Level:
</strong>
<%=
@job
.
level
%>
</div>
</div>
<div
class=
"expiration-date"
>
<div
class=
"expiration-date"
>
<strong>
Expiration date:
</strong>
<%=
@job
_details
.
expiration_date
%>
<strong>
Expiration date:
</strong>
<%=
@job
.
expiration_date
%>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div
class=
"job-description"
>
<div
class=
"job-description"
>
<%=
@job
_details
.
description
.
html_safe
%>
<%=
@job
.
description
.
html_safe
%>
</div>
</div>
</div>
</div>
<div
class=
"row under-descrip"
>
<div
class=
"row under-descrip"
>
...
...
config/routes.rb
View file @
df3204f9
Rails
.
application
.
routes
.
draw
do
Rails
.
application
.
routes
.
draw
do
# 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
resources
:jobs
resources
:jobs
get
'detail/:id'
,
action: :show
,
controller:
'jobs'
,
as: :job_detail
get
'jobs/city/:converted_name'
,
to:
'jobs#city_jobs'
,
as: :city_jobs
get
'jobs/city/:converted_name'
,
to:
'jobs#city_jobs'
,
as: :city_jobs
get
'jobs/industry/:converted_name'
,
to:
'jobs#industry_jobs'
,
as: :industry_jobs
get
'jobs/industry/:converted_name'
,
to:
'jobs#industry_jobs'
,
as: :industry_jobs
get
'jobs/company/:converted_name'
,
to:
'jobs#company_jobs'
,
as: :company_jobs
get
'jobs/company/:converted_name'
,
to:
'jobs#company_jobs'
,
as: :company_jobs
get
'detail/:id'
,
to:
'jobs#detail'
,
as: :job_detail
resources
:top_pages
resources
:top_pages
resources
:industries
resources
:industries
...
...
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