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
d06a8465
Commit
d06a8465
authored
Aug 06, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add slug for company
parent
e1c9cc35
Pipeline
#839
failed with stages
in 0 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
3 deletions
+30
-3
app/models/company.rb
+12
-0
app/views/jobs/show.html.erb
+1
-1
db/migrate/20200806093557_add_slug_to_companies.rb
+6
-0
db/schema.rb
+3
-1
lib/tasks/create_slug.rake
+8
-1
No files found.
app/models/company.rb
View file @
d06a8465
require
'./lib/common/convert_slug'
class
Company
<
ApplicationRecord
class
Company
<
ApplicationRecord
include
ConvertSlug
has_many
:jobs
has_many
:jobs
before_save
:add_slug
,
unless: :slug
private
def
add_slug
self
.
slug
=
"
#{
self
.
to_slug
(
self
.
name
)
}
-
#{
Time
.
now
.
to_i
}#{
rand
(
10000
)
}
"
end
end
end
app/views/jobs/show.html.erb
View file @
d06a8465
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<h2
class=
"font-weight-bold"
>
<%=
@job
.
title
%>
</h2>
<h2
class=
"font-weight-bold"
>
<%=
@job
.
title
%>
</h2>
<h4><i
class=
"fas fa-building"
></i>
<h4><i
class=
"fas fa-building"
></i>
<%=
link_to
@job
.
company
.
name
,
'#'
,
class:
'text-decoration-none text-dark'
%>
<%=
link_to
@job
.
company
.
name
,
jobs_path
(
model:
'company'
,
slug:
@job
.
company
.
slug
)
,
class:
'text-decoration-none text-dark'
%>
</h4>
</h4>
<span
class=
"mx-2"
><i
class=
"fas fa-map-marker-alt"
>
</i>
<span
class=
"mx-2"
><i
class=
"fas fa-map-marker-alt"
>
</i>
<%
@job
.
locations
.
each
do
|
location
|
%>
<%
@job
.
locations
.
each
do
|
location
|
%>
...
...
db/migrate/20200806093557_add_slug_to_companies.rb
0 → 100644
View file @
d06a8465
class
AddSlugToCompanies
<
ActiveRecord
::
Migration
[
5.2
]
def
change
add_column
:companies
,
:slug
,
:string
add_index
:companies
,
:slug
,
unique:
true
end
end
db/schema.rb
View file @
d06a8465
...
@@ -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:
2020_08_0
5_034659
)
do
ActiveRecord
::
Schema
.
define
(
version:
2020_08_0
6_093557
)
do
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"user_id"
t
.
bigint
"user_id"
...
@@ -30,7 +30,9 @@ ActiveRecord::Schema.define(version: 2020_08_05_034659) do
...
@@ -30,7 +30,9 @@ ActiveRecord::Schema.define(version: 2020_08_05_034659) do
t
.
string
"address"
t
.
string
"address"
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
.
string
"slug"
t
.
index
[
"name"
],
name:
"index_companies_on_name"
,
unique:
true
t
.
index
[
"name"
],
name:
"index_companies_on_name"
,
unique:
true
t
.
index
[
"slug"
],
name:
"index_companies_on_slug"
,
unique:
true
end
end
create_table
"favorites"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
create_table
"favorites"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
...
...
lib/tasks/create_slug.rake
View file @
d06a8465
...
@@ -13,6 +13,13 @@ namespace :create_slug do
...
@@ -13,6 +13,13 @@ namespace :create_slug do
end
end
end
end
desc
'Create slug model Company'
task
companies: :environment
do
Company
.
all
.
each
do
|
company
|
company
.
update_attributes
(
slug:
"
#{
company
.
to_slug
(
company
.
name
)
}
-
#{
Time
.
now
.
to_i
}#{
rand
(
10000
)
}
"
)
end
end
desc
'Create slug to all model'
desc
'Create slug to all model'
task
all:
%i[locations industries]
task
all:
%i[locations industries
companies
]
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