Add before save to check the instagram link pattern

This commit is contained in:
fabricio.albarnaz
2018-10-11 15:27:46 -03:00
parent 58a99a7f89
commit e87075aed7

View File

@@ -80,6 +80,8 @@ class Enterprise < ActiveRecord::Base
before_validation :set_unused_address_fields
after_validation :geocode_address
before_save :check_instagram_pattern
after_touch :touch_distributors
after_create :set_default_contact
after_create :relate_to_owners_enterprises
@@ -425,4 +427,9 @@ class Enterprise < ActiveRecord::Base
where('enterprises.id != ?', self.id).
each(&:touch)
end
def check_instagram_pattern
return if self.instagram.blank? || self.instagram.exclude?('www.instagram.com')
self.instagram = "@#{self.instagram.split('/').last}"
end
end