Append Logic for converted_name before save db

parent 942f54ff
Pipeline #899 canceled with stages
in 0 seconds
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def convert_attribute
self.converted_name = normalize_attribute.mb_chars.normalize(:kd).gsub(/[Đđ]/, 'd').gsub(/[^\x00-\x7F]/,'').gsub(/[\W+]/,' ').downcase.to_s.split(' ').join('-')
def convert_attribute(val)
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
class City < ApplicationRecord
before_save :convert_attribute
before_save :set_converted_name
has_many :city_jobs
has_many :jobs, through: :city_jobs
......@@ -11,7 +12,7 @@ class City < ApplicationRecord
private
def normalize_attribute
"#{name} #{rand(10000)}"
def set_converted_name
converted_name = convert_attribute(name)
end
end
class Company < ApplicationRecord
before_save :convert_attribute
before_save :set_converted_name
has_many :jobs
private
def normalize_attribute
"#{name} #{rand(10000)}"
def set_converted_name
converted_name = convert_attribute(name)
end
end
class Industry < ApplicationRecord
before_save :convert_attribute
before_save :set_converted_name
has_many :industry_jobs
has_many :jobs, through: :industry_jobs
......@@ -8,7 +9,7 @@ class Industry < ApplicationRecord
private
def normalize_attribute
"#{name} #{rand(10000)}"
def set_converted_name
converted_name = convert_attribute(name)
end
end
class Job < ApplicationRecord
before_save :convert_attribute
before_save :set_converted_name
belongs_to :company
has_many :city_jobs
has_many :cities, through: :city_jobs
......@@ -26,8 +27,8 @@ class Job < ApplicationRecord
private
def normalize_attribute
"#{title} #{rand(10000)}"
def set_converted_name
converted_name = convert_attribute(title)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment