diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 4f62d9f2f1..c91187a325 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -80,7 +80,7 @@ class Enterprise < ActiveRecord::Base before_validation :set_unused_address_fields after_validation :geocode_address - validates :instagram, format: /\A@[a-zA-Z0-9._]{1,30}\z/, :allow_blank => true + validates :instagram, format: /\A@[a-zA-Z0-9._]{1,30}\z/, allow_blank: true after_touch :touch_distributors after_create :set_default_contact @@ -333,7 +333,8 @@ class Enterprise < ActiveRecord::Base end def instagram=(value) - write_attribute(:instagram, value.try(:gsub, %r{\Ahttps?://(?:www.)?instagram.com/([a-zA-Z0-9._]{1,30})/?\z}, '@\1')) + regex = %r{\A(?:https?://)?(?:www\.)?instagram\.com/([a-zA-Z0-9._]{1,30})/?\z} + write_attribute(:instagram, value.try(:gsub, regex, '@\1')) end protected