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
d994d77f
Commit
d994d77f
authored
Aug 13, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Append Logic for converted_name before save db
parent
942f54ff
Pipeline
#899
canceled with stages
in 0 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
14 deletions
+19
-14
app/models/application_record.rb
+3
-2
app/models/city.rb
+4
-3
app/models/company.rb
+4
-3
app/models/industry.rb
+4
-3
app/models/job.rb
+4
-3
No files found.
app/models/application_record.rb
View file @
d994d77f
class
ApplicationRecord
<
ActiveRecord
::
Base
class
ApplicationRecord
<
ActiveRecord
::
Base
self
.
abstract_class
=
true
self
.
abstract_class
=
true
def
convert_attribute
def
convert_attribute
(
val
)
self
.
converted_name
=
normalize_attribute
.
mb_chars
.
normalize
(
:kd
).
gsub
(
/[Đđ]/
,
'd'
).
gsub
(
/[^\x00-\x7F]/
,
''
).
gsub
(
/[\W+]/
,
' '
).
downcase
.
to_s
.
split
(
' '
).
join
(
'-'
)
return
''
if
val
.
blank?
[
val
,
rand
(
10000
)]
=
normalize_attribute
.
mb_chars
.
normalize
(
:kd
).
gsub
(
/[Đđ]/
,
'd'
).
gsub
(
/[^\x00-\x7F]/
,
''
).
gsub
(
/[\W+]/
,
' '
).
downcase
.
to_s
.
split
(
' '
).
join
(
'-'
)
end
end
end
end
app/models/city.rb
View file @
d994d77f
class
City
<
ApplicationRecord
class
City
<
ApplicationRecord
before_save
:convert_attribute
before_save
:set_converted_name
has_many
:city_jobs
has_many
:city_jobs
has_many
:jobs
,
through: :city_jobs
has_many
:jobs
,
through: :city_jobs
...
@@ -11,7 +12,7 @@ class City < ApplicationRecord
...
@@ -11,7 +12,7 @@ class City < ApplicationRecord
private
private
def
normalize_attribut
e
def
set_converted_nam
e
"
#{
name
}
#{
rand
(
10000
)
}
"
converted_name
=
convert_attribute
(
name
)
end
end
end
end
app/models/company.rb
View file @
d994d77f
class
Company
<
ApplicationRecord
class
Company
<
ApplicationRecord
before_save
:convert_attribute
before_save
:set_converted_name
has_many
:jobs
has_many
:jobs
private
private
def
normalize_attribut
e
def
set_converted_nam
e
"
#{
name
}
#{
rand
(
10000
)
}
"
converted_name
=
convert_attribute
(
name
)
end
end
end
end
app/models/industry.rb
View file @
d994d77f
class
Industry
<
ApplicationRecord
class
Industry
<
ApplicationRecord
before_save
:convert_attribute
before_save
:set_converted_name
has_many
:industry_jobs
has_many
:industry_jobs
has_many
:jobs
,
through: :industry_jobs
has_many
:jobs
,
through: :industry_jobs
...
@@ -8,7 +9,7 @@ class Industry < ApplicationRecord
...
@@ -8,7 +9,7 @@ class Industry < ApplicationRecord
private
private
def
normalize_attribut
e
def
set_converted_nam
e
"
#{
name
}
#{
rand
(
10000
)
}
"
converted_name
=
convert_attribute
(
name
)
end
end
end
end
app/models/job.rb
View file @
d994d77f
class
Job
<
ApplicationRecord
class
Job
<
ApplicationRecord
before_save
:convert_attribute
before_save
:set_converted_name
belongs_to
:company
belongs_to
:company
has_many
:city_jobs
has_many
:city_jobs
has_many
:cities
,
through: :city_jobs
has_many
:cities
,
through: :city_jobs
...
@@ -26,8 +27,8 @@ class Job < ApplicationRecord
...
@@ -26,8 +27,8 @@ class Job < ApplicationRecord
private
private
def
normalize_attribut
e
def
set_converted_nam
e
"
#{
title
}
#{
rand
(
10000
)
}
"
converted_name
=
convert_attribute
(
title
)
end
end
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