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
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xuan Trung Le
venjob
Commits
aec2ab4b
Commit
aec2ab4b
authored
Oct 16, 2017
by
Xuan Trung Le
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix errors and optimize code.
parent
757cbfe4
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
85 additions
and
68 deletions
+85
-68
app/controllers/jobs_controller.rb
+8
-13
app/models/cities_job.rb
+4
-0
app/models/city.rb
+10
-14
app/models/industries_job.rb
+4
-0
app/models/industry.rb
+8
-9
app/models/job.rb
+4
-11
app/views/cities/index.html.erb
+1
-1
app/views/industries/_industry.html.erb
+1
-1
app/views/jobs/show.html.erb
+6
-6
config/routes.rb
+3
-3
db/migrate/20171013092752_add_jobs_count_to_cities.rb
+5
-0
db/migrate/20171016030017_add_jobs_count_to_industries.rb
+5
-0
db/schema.rb
+16
-10
lib/tasks/data.rake
+10
-0
No files found.
app/controllers/jobs_controller.rb
View file @
aec2ab4b
class
JobsController
<
ApplicationController
before_action
:set_job
,
only:
[
:show
]
def
index
@jobs
=
Job
.
all
.
order
(
updated_date:
'DESC'
).
limit
(
5
)
@jobs
=
Job
.
preload
(
:company
).
order
(
updated_date: :desc
).
limit
(
5
)
@cities
=
City
.
top_cities
@industries
=
Industry
.
top_industries
end
def
show
#code
end
def
job_lists
#code
end
def
city
city
=
City
.
find
(
params
[
:id
])
@jobs
=
city
.
jobs
.
page
(
params
[
:page
]).
per
(
20
)
city
=
City
.
find
(
params
[
:
city_
id
])
@jobs
=
city
.
jobs
.
includes
(
:company
).
page
(
params
[
:page
]).
per
(
20
)
@result
=
"jobs/City/
#{
city
.
name
}
"
render
:action
=>
:job_lists
end
def
industry
industry
=
Industry
.
find
(
params
[
:id
])
@jobs
=
industry
.
jobs
.
page
(
params
[
:page
]).
per
(
20
)
industry
=
Industry
.
find
(
params
[
:i
ndustry_i
d
])
@jobs
=
industry
.
jobs
.
includes
(
:company
).
page
(
params
[
:page
]).
per
(
20
)
@result
=
"jobs/Industry/
#{
industry
.
name
}
"
render
:
action
=>
:job_lists
render
:
template
=>
"jobs/job_lists"
end
def
company
company
=
Company
.
find
(
params
[
:id
])
company
=
Company
.
find
(
params
[
:
company_
id
])
@jobs
=
company
.
jobs
.
page
(
params
[
:page
]).
per
(
20
)
@result
=
"jobs/Company/
#{
company
.
name
}
"
render
:
action
=>
:job_lists
render
:
template
=>
"jobs/job_lists"
end
def
set_job
...
...
app/models/cities_job.rb
0 → 100644
View file @
aec2ab4b
class
CitiesJob
<
ApplicationRecord
belongs_to
:city
,
counter_cache: :jobs_count
belongs_to
:job
end
app/models/city.rb
View file @
aec2ab4b
class
City
<
ApplicationRecord
belongs_to
:country
,
optional:
true
has_and_belongs_to_many
:companies
has_and_belongs_to_many
:jobs
has_many
:cities_jobs
has_many
:jobs
,
through: :cities_jobs
scope
:top_cities
,
->
{
select
(
'cities.id, cities.name AS name, COUNT(jobs.id) AS jobs_count'
).
joins
(
:jobs
).
group
(
'cities.id'
).
order
(
'jobs_count DESC, name'
).
limit
(
9
)
}
scope
:top_cities
,
->
{
select
(
'id, name, jobs_count'
).
where
(
'jobs_count > 0'
).
order
(
jobs_count: :desc
).
limit
(
9
)
}
scope
:city_list
,
->
{
select
(
'cities.id, cities.name AS name, countries.name AS country_name,
COUNT(jobs.id) AS jobs_count'
).
joins
(
:jobs
).
joins
(
:country
)
.
# where('jobs_count >= 1').
group
(
'cities.id'
).
order
(
'jobs_count DESC, name'
)
}
scope
:city_list
,
->
{
select
(
'cities.id, cities.name AS name, countries.name AS country_name, cities.jobs_count'
).
joins
(
:country
).
where
(
'jobs_count > 0'
).
order
(
'jobs_count DESC, name'
)
}
scope
:get_job
,
->
id
{
find
(
id
)
}
end
app/models/industries_job.rb
0 → 100644
View file @
aec2ab4b
class
IndustriesJob
<
ApplicationRecord
belongs_to
:industry
,
counter_cache: :jobs_count
belongs_to
:job
end
app/models/industry.rb
View file @
aec2ab4b
class
Industry
<
ApplicationRecord
has_and_belongs_to_many
:jobs
# has_and_belongs_to_many :jobs
has_many
:industries_jobs
has_many
:jobs
,
through: :industries_jobs
scope
:top_industries
,
->
{
select
(
'industries.id, industries.name AS name, COUNT(jobs.id) AS jobs_count'
).
joins
(
:jobs
).
group
(
'industries.id'
).
scope
:top_industries
,
->
{
select
(
'id, name, jobs_count'
).
where
(
'jobs_count > 0'
).
order
(
'jobs_count DESC, name'
).
limit
(
9
)
}
scope
:industry_list
,
->
{
select
(
'industries.id, industries.name AS name, COUNT(jobs.id) AS jobs_count'
).
joins
(
:jobs
)
.
# where('jobs_count >= 1').
group
(
'industries.id'
).
order
(
'jobs_count DESC, name'
)
}
scope
:industry_list
,
->
{
select
(
'id, name, jobs_count'
).
where
(
'jobs_count > 0'
).
order
(
'jobs_count DESC, name'
)
}
end
app/models/job.rb
View file @
aec2ab4b
...
...
@@ -4,8 +4,10 @@ class Job < ApplicationRecord
has_many
:candidates
,
through: :apply_jobs
,
class_name:
'User'
,
source: :user
has_many
:favorite_jobs
has_many
:people_who_liked
,
through: :favorite_jobs
,
class_name:
'User'
,
source: :user
has_and_belongs_to_many
:industries
has_and_belongs_to_many
:cities
has_many
:industries_jobs
has_many
:industries
,
through: :industries_jobs
has_many
:cities_jobs
has_many
:cities
,
through: :cities_jobs
def
self
.
create_new_jobs
(
arr_jobs
)
arr_jobs
.
each
do
|
item
|
...
...
@@ -27,7 +29,6 @@ class Job < ApplicationRecord
end
# Company
<<<<<<<
91
b545e3685a56b535c9905838040868191d9dc5
company
=
Company
.
find_by
(
name:
item
[
:company_name
])
if
company
.
nil?
company
=
Company
.
create
(
name:
item
[
:company_name
],
...
...
@@ -35,15 +36,7 @@ class Job < ApplicationRecord
description:
item
[
:company_description
])
end
job
.
company
=
company
job
.
company
.
cities
<<
(
job
.
cities
-
job
.
company
.
cities
)
=======
job
.
company
=
Company
.
find_or_initialize_by
(
name:
item
[
:company_name
])
job
.
company
.
location
=
item
[
:company_location
]
job
.
company
.
description
=
item
[
:company_description
]
job
.
company
.
cities
=
job
.
cities
# job.company.save
>>>>>>>
Create
the
TOP
,
industry_list
,
city_list
,
job_detail
pages
.
# Industry
unless
item
[
:industry
].
blank?
...
...
app/views/cities/index.html.erb
View file @
aec2ab4b
...
...
@@ -13,7 +13,7 @@
<%-
if
city
.
country_name
.
eql?
(
Country
::
VIETNAM
)
-%>
<div
class=
"col-md-3 maxH109"
>
<div
class=
"job-intro well mr0 mrBot20 maxH89"
>
<h4
class=
"mr0"
>
<%=
link_to
city
.
name
,
"
#{
jobs_path
}
/city/
#{
city
.
id
}
"
%>
</h4>
<h4
class=
"mr0"
>
<%=
link_to
city
.
name
,
_city_jobs_path
(
city
)
%>
</h4>
<p>
Jobs:
<span
class=
"badge"
>
<%=
city
.
jobs_count
%>
</span></p>
</div>
</div>
...
...
app/views/industries/_industry.html.erb
View file @
aec2ab4b
<div
class=
"col-md-
<%=
column
%>
maxH109"
>
<div
class=
"job-intro well mr0 mrBot20 maxH89"
>
<h4
class=
"mr0"
>
<%=
link_to
industry
.
name
,
"
#{
jobs_path
}
/industry/
#{
industry
.
id
}
"
%>
</h4>
<h4
class=
"mr0"
>
<%=
link_to
industry
.
name
,
_industry_jobs_path
(
industry
)
%>
</h4>
<p>
Jobs:
<span
class=
"badge"
>
<%=
industry
.
jobs_count
%>
</span></p>
</div>
</div>
app/views/jobs/show.html.erb
View file @
aec2ab4b
...
...
@@ -5,13 +5,13 @@
<li>
<%-
@job
.
cities
.
each_with_index
do
|
city
,
index
|
-%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
link_to
city
.
name
,
"
#{
jobs_path
}
/city/
#{
city
.
id
}
"
%>
<%=
link_to
city
.
name
,
_city_jobs_path
(
city
)
%>
<%-
end
-%>
</li>
<li>
<%-
@job
.
industries
.
each_with_index
do
|
industry
,
index
|
-%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
link_to
industry
.
name
,
"
#{
jobs_path
}
/industry/
#{
industry
.
id
}
"
%>
<%=
link_to
industry
.
name
,
_industry_jobs_path
(
industry
)
%>
<%-
end
-%>
</li>
<li>
<%=
@job
.
name
%>
</li>
...
...
@@ -20,11 +20,11 @@
<div
class=
"job"
>
<div
class=
"col-md-9"
>
<h1>
2.
<%=
@job
.
name
%>
</h1>
<p>
3.
<%=
link_to
@job
.
company
.
name
,
"
#{
jobs_path
}
/company/
#{
@job
.
company
.
id
}
"
%>
</p>
<p>
3.
<%=
link_to
@job
.
company
.
name
,
_company_jobs_path
(
@job
.
company
)
%>
</p>
<p>
4. Location:
<%-
@job
.
cities
.
each_with_index
do
|
city
,
index
|
-%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
link_to
city
.
name
,
"
#{
jobs_path
}
/city/
#{
city
.
id
}
"
%>
<%=
link_to
city
.
name
,
_city_jobs_path
(
city
)
%>
<%-
end
-%>
</p>
<p>
5. Salary:
<%=
@job
.
salary
%>
</p>
...
...
@@ -33,11 +33,11 @@
</p>
</div>
<div
class=
"col-md-3"
>
<%=
link_to
"Ap
l
ly"
,
"#"
,
class:
"btn btn-primary btn-lg"
%>
<%=
link_to
"Ap
p
ly"
,
"#"
,
class:
"btn btn-primary btn-lg"
%>
</div>
<div
class=
"action"
>
<div
class=
"col-md-6"
>
<%=
link_to
"Ap
l
ly"
,
"#"
,
class:
"btn btn-default btn-lg"
%>
<%=
link_to
"Ap
p
ly"
,
"#"
,
class:
"btn btn-default btn-lg"
%>
</div>
<div
class=
"col-md-6"
>
<%=
link_to
"Favorite"
,
"#"
,
class:
"btn btn-default btn-lg"
%>
...
...
config/routes.rb
View file @
aec2ab4b
...
...
@@ -5,9 +5,9 @@ Rails.application.routes.draw do
get
'cities'
=>
'cities#index'
get
'industries'
=>
"industries#index"
collection
do
get
'city/:
id'
=>
"jobs#city"
get
'industry/:i
d'
=>
"jobs#industry"
get
'company/:
id'
=>
"jobs#company"
get
'city/:
city_id'
=>
"jobs#city"
,
as: :_city
get
'industry/:i
ndustry_id'
=>
"jobs#industry"
,
as: :_industry
get
'company/:
company_id'
=>
"jobs#company"
,
as: :_company
end
end
root
'jobs#index'
...
...
db/migrate/20171013092752_add_jobs_count_to_cities.rb
0 → 100644
View file @
aec2ab4b
class
AddJobsCountToCities
<
ActiveRecord
::
Migration
[
5.1
]
def
change
add_column
:cities
,
:jobs_count
,
:integer
,
default:
0
end
end
db/migrate/20171016030017_add_jobs_count_to_industries.rb
0 → 100644
View file @
aec2ab4b
class
AddJobsCountToIndustries
<
ActiveRecord
::
Migration
[
5.1
]
def
change
add_column
:industries
,
:jobs_count
,
:integer
,
default:
0
end
end
db/schema.rb
View file @
aec2ab4b
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201710
05085453
)
do
ActiveRecord
::
Schema
.
define
(
version:
201710
16030017
)
do
create_table
"apply_jobs"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
t
.
bigint
"job_id"
...
...
@@ -27,21 +27,22 @@ ActiveRecord::Schema.define(version: 20171005085453) do
t
.
bigint
"country_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
integer
"jobs_count"
,
default:
0
t
.
index
[
"country_id"
],
name:
"index_cities_on_country_id"
end
create_table
"cities_companies"
,
id:
false
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
t
.
bigint
"c
ity_id"
,
null:
false
t
.
bigint
"c
ompany_id"
,
null:
false
t
.
index
[
"city_id"
,
"company_id"
],
name:
"index_cities_companies_on_city_id_and_compan
y_id"
t
.
index
[
"company_id"
,
"city_id"
],
name:
"index_cities_companies_on_company_id_and_cit
y_id"
t
.
bigint
"c
ompany_id"
t
.
bigint
"c
ity_id"
t
.
index
[
"city_id"
],
name:
"index_cities_companies_on_cit
y_id"
t
.
index
[
"company_id"
],
name:
"index_cities_companies_on_compan
y_id"
end
create_table
"cities_jobs"
,
id:
false
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
t
.
bigint
"job_id"
,
null:
false
t
.
bigint
"city_id"
,
null:
false
t
.
index
[
"city_id"
,
"job_id"
],
name:
"index_cities_jobs_on_city_id_and_job
_id"
t
.
index
[
"job_id"
,
"city_id"
],
name:
"index_cities_jobs_on_job_id_and_city
_id"
create_table
"cities_jobs"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
t
.
bigint
"job_id"
t
.
bigint
"city_id"
t
.
index
[
"city_id"
],
name:
"index_cities_jobs_on_city
_id"
t
.
index
[
"job_id"
],
name:
"index_cities_jobs_on_job
_id"
end
create_table
"companies"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
...
...
@@ -71,6 +72,7 @@ ActiveRecord::Schema.define(version: 20171005085453) do
t
.
string
"name"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
integer
"jobs_count"
,
default:
0
end
create_table
"industries_jobs"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
...
...
@@ -112,6 +114,10 @@ ActiveRecord::Schema.define(version: 20171005085453) do
t
.
datetime
"updated_at"
,
null:
false
t
.
string
"cv"
t
.
string
"name"
t
.
string
"confirmation_token"
t
.
datetime
"confirmed_at"
t
.
datetime
"confirmation_sent_at"
t
.
index
[
"confirmation_token"
],
name:
"index_users_on_confirmation_token"
,
unique:
true
t
.
index
[
"email"
],
name:
"index_users_on_email"
,
unique:
true
t
.
index
[
"reset_password_token"
],
name:
"index_users_on_reset_password_token"
,
unique:
true
end
...
...
lib/tasks/data.rake
View file @
aec2ab4b
...
...
@@ -7,4 +7,14 @@ namespace :data do
@data
=
Crawler
.
crawl_job_infomation
(
links
)
Job
.
create_new_jobs
(
@data
)
end
desc
"reset counter industry"
task
reset_counter_industry: :environment
do
|
t
|
Industry
.
find_each
{
|
industry
|
Industry
.
reset_counters
(
industry
.
id
,
:jobs
)
}
end
desc
"reset counter city"
task
reset_counter_job: :environment
do
|
t
|
City
.
find_each
{
|
city
|
City
.
reset_counters
(
city
.
id
,
:jobs
)
}
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