diff --git a/app/models/r_template.rb b/app/models/r_template.rb index 2fa8747..deb22bf 100644 --- a/app/models/r_template.rb +++ b/app/models/r_template.rb @@ -16,7 +16,7 @@ class RTemplate field :sold, :type => Boolean, :default => false field :git_url field :git_branch - field :allow_domain, type: String, default: '' + field :allow_domain #change from String to Array field :installed_site_tokens, type: Array, default: [] mount_uploader :template_zip, AssetUploader @@ -25,6 +25,26 @@ class RTemplate accepts_nested_attributes_for :template_image_files, :allow_destroy => true accepts_nested_attributes_for :template_psd_file, :allow_destroy => true + before_save do + if self.allow_domain.class == String + self.allow_domain = self.allow_domain.split(",").map{|s| s.strip} + elsif self.allow_domain.nil? + self.allow_domain = [] + end + end + after_initialize do + unless self.new_record? + save_flag = false + if self.allow_domain.class == String + self.allow_domain = self.allow_domain.split(",").map{|s| s.strip} + save_flag = true + elsif self.allow_domain.nil? + self.allow_domain = [] + save_flag = true + end + self.save(:validate=>false) if save_flag + end + end def template_zip(origin_flag=false) if self.git_url.blank? || self.git_branch.blank? || origin_flag super()