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
8aac2ef3
Commit
8aac2ef3
authored
Aug 10, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move Constant Variable to model, append relationship
parent
a8e034a4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
11 deletions
+8
-11
app/controllers/cities_controller.rb
+2
-4
app/models/city.rb
+3
-0
app/models/job.rb
+1
-1
lib/src/crawler.rb
+2
-6
No files found.
app/controllers/cities_controller.rb
View file @
8aac2ef3
class
CitiesController
<
ApplicationController
class
CitiesController
<
ApplicationController
VIETNAM
=
1
FOREIGN
=
0
def
index
def
index
@cities_vietnam
=
City
.
location
(
VIETNAM
)
@cities_vietnam
=
City
.
location
(
City
::
VIETNAM
)
@cities_international
=
City
.
location
(
FOREIGN
)
@cities_international
=
City
.
location
(
City
::
FOREIGN
)
end
end
end
end
app/models/city.rb
View file @
8aac2ef3
...
@@ -2,6 +2,9 @@ class City < ApplicationRecord
...
@@ -2,6 +2,9 @@ class City < ApplicationRecord
has_many
:city_jobs
has_many
:city_jobs
has_many
:jobs
,
through: :city_jobs
has_many
:jobs
,
through: :city_jobs
VIETNAM
=
1
FOREIGN
=
0
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
)
}
end
end
app/models/job.rb
View file @
8aac2ef3
...
@@ -15,7 +15,7 @@ class Job < ApplicationRecord
...
@@ -15,7 +15,7 @@ class Job < ApplicationRecord
has_many
:histories
has_many
:histories
has_many
:users
,
through: :histories
has_many
:users
,
through: :histories
scope
:limit_job
,
->
{
limit
(
5
).
order
(
created_at: :desc
)
}
scope
:limit_job
,
->
{
includes
(
:cities
,
:company
).
order
(
created_at: :desc
).
limit
(
5
)
}
scope
:all_job
,
->
{
limit
(
20
).
order
(
created_at: :desc
)
}
scope
:all_job
,
->
{
limit
(
20
).
order
(
created_at: :desc
)
}
def
company_name
def
company_name
...
...
lib/src/crawler.rb
View file @
8aac2ef3
...
@@ -45,9 +45,7 @@ class Crawler
...
@@ -45,9 +45,7 @@ class Crawler
cities_relationship
=
City
.
where
(
name:
location_relationship
)
cities_relationship
=
City
.
where
(
name:
location_relationship
)
city_job_relationship
=
CityJob
.
where
(
job_id:
job
.
id
,
city_id:
cities_relationship
.
ids
)
city_job_relationship
=
CityJob
.
where
(
job_id:
job
.
id
,
city_id:
cities_relationship
.
ids
)
if
city_job_relationship
.
blank?
job
.
cities
<<
cities_relationship
if
city_job_relationship
.
blank?
job
.
cities
<<
cities_relationship
end
end
end
def
industry_relationship
(
row
,
job
)
def
industry_relationship
(
row
,
job
)
...
@@ -55,9 +53,7 @@ class Crawler
...
@@ -55,9 +53,7 @@ class Crawler
industries_relationship
=
Industry
.
where
(
name:
industry_relationship
)
industries_relationship
=
Industry
.
where
(
name:
industry_relationship
)
industry_job_relationship
=
IndustryJob
.
where
(
job_id:
job
.
id
,
industry_id:
industries_relationship
.
ids
)
industry_job_relationship
=
IndustryJob
.
where
(
job_id:
job
.
id
,
industry_id:
industries_relationship
.
ids
)
if
industry_job_relationship
.
blank?
job
.
industries
<<
industries_relationship
if
industry_job_relationship
.
blank?
job
.
industries
<<
industries_relationship
end
end
end
def
create_job
(
title
,
link_page
,
row
,
company
)
def
create_job
(
title
,
link_page
,
row
,
company
)
...
...
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