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
ba5171d1
Commit
ba5171d1
authored
Oct 16, 2017
by
Xuan Trung Le
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix errors
parent
94090d82
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
46 additions
and
35 deletions
+46
-35
app/controllers/jobs_controller.rb
+4
-4
app/models/city.rb
+4
-4
app/models/industry.rb
+6
-7
app/views/cities/_city.html.erb
+1
-1
app/views/cities/index.html.erb
+2
-2
app/views/industries/_industry.html.erb
+1
-1
app/views/jobs/show.html.erb
+7
-7
config/routes.rb
+8
-8
db/migrate/20171016091751_add_index_to_cities.rb
+5
-0
db/migrate/20171016091830_add_index_to_industries.rb
+5
-0
db/schema.rb
+3
-1
No files found.
app/controllers/jobs_controller.rb
View file @
ba5171d1
class
JobsController
<
ApplicationController
class
JobsController
<
ApplicationController
before_action
:set_job
,
only:
[
:show
]
before_action
:set_job
,
only:
[
:show
]
def
index
def
index
@jobs
=
Job
.
preload
(
:company
).
order
(
updated_date: :desc
).
limit
(
5
)
@jobs
=
Job
.
includes
(
:company
).
order
(
updated_date: :desc
).
limit
(
5
)
@cities
=
City
.
top_cities
@cities
=
City
.
top_cities
@industries
=
Industry
.
top_industries
@industries
=
Industry
.
top_industries
end
end
...
@@ -13,21 +13,21 @@ class JobsController < ApplicationController
...
@@ -13,21 +13,21 @@ class JobsController < ApplicationController
city
=
City
.
find
(
params
[
:city_id
])
city
=
City
.
find
(
params
[
:city_id
])
@jobs
=
city
.
jobs
.
includes
(
:company
).
page
(
params
[
:page
]).
per
(
20
)
@jobs
=
city
.
jobs
.
includes
(
:company
).
page
(
params
[
:page
]).
per
(
20
)
@result
=
"jobs/City/
#{
city
.
name
}
"
@result
=
"jobs/City/
#{
city
.
name
}
"
render
:action
=>
:job_lists
render
template:
"jobs/job_lists"
end
end
def
industry
def
industry
industry
=
Industry
.
find
(
params
[
:industry_id
])
industry
=
Industry
.
find
(
params
[
:industry_id
])
@jobs
=
industry
.
jobs
.
includes
(
:company
).
page
(
params
[
:page
]).
per
(
20
)
@jobs
=
industry
.
jobs
.
includes
(
:company
).
page
(
params
[
:page
]).
per
(
20
)
@result
=
"jobs/Industry/
#{
industry
.
name
}
"
@result
=
"jobs/Industry/
#{
industry
.
name
}
"
render
:template
=>
"jobs/job_lists"
render
template:
"jobs/job_lists"
end
end
def
company
def
company
company
=
Company
.
find
(
params
[
:company_id
])
company
=
Company
.
find
(
params
[
:company_id
])
@jobs
=
company
.
jobs
.
page
(
params
[
:page
]).
per
(
20
)
@jobs
=
company
.
jobs
.
page
(
params
[
:page
]).
per
(
20
)
@result
=
"jobs/Company/
#{
company
.
name
}
"
@result
=
"jobs/Company/
#{
company
.
name
}
"
render
:template
=>
"jobs/job_lists"
render
template:
"jobs/job_lists"
end
end
def
set_job
def
set_job
...
...
app/models/city.rb
View file @
ba5171d1
...
@@ -4,14 +4,14 @@ class City < ApplicationRecord
...
@@ -4,14 +4,14 @@ class City < ApplicationRecord
has_many
:cities_jobs
has_many
:cities_jobs
has_many
:jobs
,
through: :cities_jobs
has_many
:jobs
,
through: :cities_jobs
scope
:top_cities
,
->
{
select
(
'id, name, jobs_count'
).
scope
:top_cities
,
->
{
have_at_least_one_job
.
where
(
'jobs_count > 0'
).
order
(
jobs_count: :desc
).
order
(
jobs_count: :desc
).
limit
(
9
)
}
limit
(
9
)
}
scope
:city_list
,
->
{
select
(
'cities.id, cities.name AS name, countries.name AS country_name, cities.jobs_count'
).
scope
:city_list
,
->
{
select
(
'cities.id, cities.name AS name, countries.name AS country_name, cities.jobs_count'
).
joins
(
:country
).
joins
(
:country
).
where
(
'jobs_count > 0'
)
.
have_at_least_one_job
.
order
(
'jobs_count DESC, name'
)
}
order
(
jobs_count: :desc
,
name: :asc
)
}
scope
:have_at_least_one_job
,
->
{
where
(
'jobs_count > 0'
)}
end
end
app/models/industry.rb
View file @
ba5171d1
class
Industry
<
ApplicationRecord
class
Industry
<
ApplicationRecord
# has_and_belongs_to_many :jobs
has_many
:industries_jobs
has_many
:industries_jobs
has_many
:jobs
,
through: :industries_jobs
has_many
:jobs
,
through: :industries_jobs
scope
:top_industries
,
->
{
select
(
'id, name, jobs_count'
).
scope
:top_industries
,
->
{
have_at_least_one_job
.
where
(
'jobs_count > 0'
).
order
(
jobs_count: :desc
,
name: :asc
).
order
(
'jobs_count DESC, name'
).
limit
(
9
)
}
limit
(
9
)
}
scope
:industry_list
,
->
{
select
(
'id, name, jobs_count'
).
scope
:industry_list
,
->
{
have_at_least_one_job
.
where
(
'jobs_count > 0'
).
order
(
jobs_count: :desc
)
}
order
(
'jobs_count DESC, name'
)
}
scope
:have_at_least_one_job
,
->
{
where
(
'jobs_count > 0'
)}
end
end
app/views/cities/_city.html.erb
View file @
ba5171d1
<div
class=
"col-md-
<%=
column
%>
"
>
<div
class=
"col-md-
<%=
column
%>
"
>
<div
class=
"job-intro well mr0 mrBot20"
id=
"vietnam"
>
<div
class=
"job-intro well mr0 mrBot20"
id=
"vietnam"
>
<h4
class=
"mr0"
>
<%=
link_to
city
.
name
,
_
city_jobs_path
(
city
)
%>
</h4>
<h4
class=
"mr0"
>
<%=
link_to
city
.
name
,
city_jobs_path
(
city
)
%>
</h4>
<p>
Jobs:
<span
class=
"badge"
>
<%=
city
.
jobs_count
%>
</span></p>
<p>
Jobs:
<span
class=
"badge"
>
<%=
city
.
jobs_count
%>
</span></p>
</div>
</div>
</div>
</div>
app/views/cities/index.html.erb
View file @
ba5171d1
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<%-
if
city
.
country_name
.
eql?
(
Country
::
VIETNAM
)
-%>
<%-
if
city
.
country_name
.
eql?
(
Country
::
VIETNAM
)
-%>
<div
class=
"col-md-3 maxH109"
>
<div
class=
"col-md-3 maxH109"
>
<div
class=
"job-intro well mr0 mrBot20 maxH89"
>
<div
class=
"job-intro well mr0 mrBot20 maxH89"
>
<h4
class=
"mr0"
>
<%=
link_to
city
.
name
,
_
city_jobs_path
(
city
)
%>
</h4>
<h4
class=
"mr0"
>
<%=
link_to
city
.
name
,
city_jobs_path
(
city
)
%>
</h4>
<p>
Jobs:
<span
class=
"badge"
>
<%=
city
.
jobs_count
%>
</span></p>
<p>
Jobs:
<span
class=
"badge"
>
<%=
city
.
jobs_count
%>
</span></p>
</div>
</div>
</div>
</div>
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
<%-
if
city
.
country_name
.
eql?
(
Country
::
ANOTHER
)
-%>
<%-
if
city
.
country_name
.
eql?
(
Country
::
ANOTHER
)
-%>
<div
class=
"col-md-3 maxH109"
>
<div
class=
"col-md-3 maxH109"
>
<div
class=
"job-intro well mr0 mrBot20 maxH89"
>
<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>
<p>
Jobs:
<span
class=
"badge"
>
<%=
city
.
jobs_count
%>
</span></p>
</div>
</div>
</div>
</div>
...
...
app/views/industries/_industry.html.erb
View file @
ba5171d1
<div
class=
"col-md-
<%=
column
%>
maxH109"
>
<div
class=
"col-md-
<%=
column
%>
maxH109"
>
<div
class=
"job-intro well mr0 mrBot20 maxH89"
>
<div
class=
"job-intro well mr0 mrBot20 maxH89"
>
<h4
class=
"mr0"
>
<%=
link_to
industry
.
name
,
_
industry_jobs_path
(
industry
)
%>
</h4>
<h4
class=
"mr0"
>
<%=
link_to
industry
.
name
,
industry_jobs_path
(
industry
)
%>
</h4>
<p>
Jobs:
<span
class=
"badge"
>
<%=
industry
.
jobs_count
%>
</span></p>
<p>
Jobs:
<span
class=
"badge"
>
<%=
industry
.
jobs_count
%>
</span></p>
</div>
</div>
</div>
</div>
app/views/jobs/show.html.erb
View file @
ba5171d1
...
@@ -4,14 +4,14 @@
...
@@ -4,14 +4,14 @@
<li><a
href=
"/"
>
TOP
</a></li>
<li><a
href=
"/"
>
TOP
</a></li>
<li>
<li>
<%-
@job
.
cities
.
each_with_index
do
|
city
,
index
|
-%>
<%-
@job
.
cities
.
each_with_index
do
|
city
,
index
|
-%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
link_to
city
.
name
,
_
city_jobs_path
(
city
)
%>
<%=
link_to
city
.
name
,
city_jobs_path
(
city
)
%>
<%-
end
-%>
<%-
end
-%>
</li>
</li>
<li>
<li>
<%-
@job
.
industries
.
each_with_index
do
|
industry
,
index
|
-%>
<%-
@job
.
industries
.
each_with_index
do
|
industry
,
index
|
-%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
link_to
industry
.
name
,
_
industry_jobs_path
(
industry
)
%>
<%=
link_to
industry
.
name
,
industry_jobs_path
(
industry
)
%>
<%-
end
-%>
<%-
end
-%>
</li>
</li>
<li>
<%=
@job
.
name
%>
</li>
<li>
<%=
@job
.
name
%>
</li>
...
@@ -20,11 +20,11 @@
...
@@ -20,11 +20,11 @@
<div
class=
"job"
>
<div
class=
"job"
>
<div
class=
"col-md-9"
>
<div
class=
"col-md-9"
>
<h1>
2.
<%=
@job
.
name
%>
</h1>
<h1>
2.
<%=
@job
.
name
%>
</h1>
<p>
3.
<%=
link_to
@job
.
company
.
name
,
_
company_jobs_path
(
@job
.
company
)
%>
</p>
<p>
3.
<%=
link_to
@job
.
company
.
name
,
company_jobs_path
(
@job
.
company
)
%>
</p>
<p>
4. Location:
<p>
4. Location:
<%-
@job
.
cities
.
each_with_index
do
|
city
,
index
|
-%>
<%-
@job
.
cities
.
each_with_index
do
|
city
,
index
|
-%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
"
#{
index
>
0
?
','
:
''
}
"
%>
<%=
link_to
city
.
name
,
_
city_jobs_path
(
city
)
%>
<%=
link_to
city
.
name
,
city_jobs_path
(
city
)
%>
<%-
end
-%>
<%-
end
-%>
</p>
</p>
<p>
5. Salary:
<%=
@job
.
salary
%>
</p>
<p>
5. Salary:
<%=
@job
.
salary
%>
</p>
...
...
config/routes.rb
View file @
ba5171d1
Rails
.
application
.
routes
.
draw
do
Rails
.
application
.
routes
.
draw
do
root
'jobs#index'
devise_for
:users
devise_for
:users
get
'jobs/index'
resources
:cities
,
:industries
,
:jobs
do
resources
:cities
,
only:
[
:index
,
:show
]
get
'cities'
=>
'cities#index'
resources
:industries
,
only:
[
:index
,
:show
]
get
'industries'
=>
"industries#index"
resources
:jobs
do
collection
do
collection
do
get
'city/:city_id'
=>
"jobs#city"
,
as: :
_
city
get
'city/:city_id'
=>
"jobs#city"
,
as: :city
get
'industry/:industry_id'
=>
"jobs#industry"
,
as: :
_
industry
get
'industry/:industry_id'
=>
"jobs#industry"
,
as: :industry
get
'company/:company_id'
=>
"jobs#company"
,
as: :
_
company
get
'company/:company_id'
=>
"jobs#company"
,
as: :company
end
end
end
end
root
'jobs#index'
end
end
db/migrate/20171016091751_add_index_to_cities.rb
0 → 100644
View file @
ba5171d1
class
AddIndexToCities
<
ActiveRecord
::
Migration
[
5.1
]
def
change
add_index
:cities
,
:jobs_count
end
end
db/migrate/20171016091830_add_index_to_industries.rb
0 → 100644
View file @
ba5171d1
class
AddIndexToIndustries
<
ActiveRecord
::
Migration
[
5.1
]
def
change
add_index
:industries
,
:jobs_count
end
end
db/schema.rb
View file @
ba5171d1
...
@@ -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:
201710160
30017
)
do
ActiveRecord
::
Schema
.
define
(
version:
201710160
91830
)
do
create_table
"apply_jobs"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
create_table
"apply_jobs"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
t
.
bigint
"job_id"
t
.
bigint
"job_id"
...
@@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do
...
@@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
integer
"jobs_count"
,
default:
0
t
.
integer
"jobs_count"
,
default:
0
t
.
index
[
"country_id"
],
name:
"index_cities_on_country_id"
t
.
index
[
"country_id"
],
name:
"index_cities_on_country_id"
t
.
index
[
"jobs_count"
],
name:
"index_cities_on_jobs_count"
end
end
create_table
"cities_companies"
,
id:
false
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
create_table
"cities_companies"
,
id:
false
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
...
@@ -73,6 +74,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do
...
@@ -73,6 +74,7 @@ ActiveRecord::Schema.define(version: 20171016030017) 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
.
integer
"jobs_count"
,
default:
0
t
.
integer
"jobs_count"
,
default:
0
t
.
index
[
"jobs_count"
],
name:
"index_industries_on_jobs_count"
end
end
create_table
"industries_jobs"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
create_table
"industries_jobs"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
...
...
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