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
03ee3000
Commit
03ee3000
authored
Jul 31, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create scope select top locations, industries
parent
e175a0c0
Pipeline
#744
failed with stages
in 0 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
20 deletions
+14
-20
app/controllers/home_controller.rb
+3
-13
app/models/industry.rb
+2
-0
app/models/job.rb
+2
-0
app/models/location.rb
+3
-1
app/views/home/_city.html.erb
+1
-2
app/views/home/_industry.html.erb
+1
-2
app/views/home/index.html.erb
+2
-2
No files found.
app/controllers/home_controller.rb
View file @
03ee3000
...
...
@@ -3,18 +3,8 @@ class HomeController < ApplicationController
@total_jobs
=
Job
.
count
@locations
=
Location
.
all
@industries
=
Industry
.
all
@jobs
=
Job
.
order
(
created_at: :desc
).
limit
(
6
)
@top_cities
=
list_top_of
(
@locations
,
9
)
@top_industries
=
list_top_of
(
@industries
,
9
)
end
private
def
list_top_of
(
list_object
,
number
)
top_object
=
{}
list_object
.
each
do
|
object
|
top_object
[
object
.
id
]
=
object
.
jobs
.
count
end
top_object
.
sort_by
{
|
_k
,
v
|
v
}.
reverse
.
take
(
number
)
@jobs
=
Job
.
order
(
created_at: :desc
).
limit
(
Job
::
NUMBER_LATEST_JOB
)
@top_cities
=
Location
.
top_locations
(
9
)
@top_industries
=
Industry
.
top_industries
(
9
)
end
end
app/models/industry.rb
View file @
03ee3000
class
Industry
<
ApplicationRecord
scope
:top_industries
,
->
(
number
)
{
joins
(
:jobs
).
group
(
:industry_id
).
order
(
Arel
.
sql
(
'count(jobs.id) DESC'
)).
take
(
number
)
}
has_and_belongs_to_many
:jobs
end
app/models/job.rb
View file @
03ee3000
class
Job
<
ApplicationRecord
NUMBER_LATEST_JOB
=
6
belongs_to
:company
has_many
:applied_jobs
has_many
:histories
...
...
app/models/location.rb
View file @
03ee3000
class
Location
<
ApplicationRecord
CITY_VIETNAM_NUMBER
=
70
.
freeze
scope
:top_locations
,
->
(
number
)
{
joins
(
:jobs
).
group
(
:location_id
).
order
(
Arel
.
sql
(
'count(jobs.id) DESC'
)).
take
(
number
)
}
CITY_VIETNAM_NUMBER
=
70
has_many
:locations_jobs
has_many
:jobs
,
through: :locations_jobs
...
...
app/views/home/_city.html.erb
View file @
03ee3000
<%
location
=
Location
.
find_by
(
id:
object
[
0
])
%>
<div
class=
'col-4 my-2'
>
<div
class=
'card'
>
<%=
link_to
'#'
,
class:
'card-body text-decoration-none'
do
%>
<h5
class=
'card-title font-weight-bold'
>
<%=
location
.
city
%>
</h5>
<p
class=
'card-text'
>
<%=
object
[
1
]
%>
Jobs
</p>
<p
class=
'card-text'
>
<%=
location
.
jobs
.
size
%>
Jobs
</p>
<%
end
%>
</div>
</div>
app/views/home/_industry.html.erb
View file @
03ee3000
<%
industry
=
Industry
.
find_by
(
id:
object
[
0
])
%>
<div
class=
'col-4 my-2'
>
<div
class=
'card'
>
<%=
link_to
'#'
,
class:
'card-body text-decoration-none'
do
%>
<h5
class=
'card-title font-weight-bold'
>
<%=
industry
.
name
%>
</h5>
<p
class=
'card-text'
>
<%=
object
[
1
]
%>
Jobs
</p>
<p
class=
'card-text'
>
<%=
industry
.
jobs
.
size
%>
Jobs
</p>
<%
end
%>
</div>
</div>
app/views/home/index.html.erb
View file @
03ee3000
...
...
@@ -16,14 +16,14 @@
<div
id=
'top-city'
class=
'my-4 text-center'
>
<h1>
Top Cities
</h1>
<div
class=
'row'
>
<%=
render
partial:
'home/city'
,
collection:
@top_cities
,
as: :
object
%>
<%=
render
partial:
'home/city'
,
collection:
@top_cities
,
as: :
location
%>
</div>
<a
href=
'#'
>
See more...
</a>
</div>
<div
id=
'top-industry'
class=
'my-4 text-center'
>
<h1>
Top Industries
</h1>
<div
class=
'row'
>
<%=
render
partial:
'home/industry'
,
collection:
@top_industries
,
as: :
object
%>
<%=
render
partial:
'home/industry'
,
collection:
@top_industries
,
as: :
industry
%>
</div>
<a
href=
'#'
>
See more...
</a>
</div>
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