Change allow_domain to Array.

This commit is contained in:
BoHung Chiu 2021-05-11 10:25:04 +08:00
parent d203d79c8b
commit 710157d098
1 changed files with 21 additions and 1 deletions

View File

@ -16,7 +16,7 @@ class RTemplate
field :sold, :type => Boolean, :default => false field :sold, :type => Boolean, :default => false
field :git_url field :git_url
field :git_branch field :git_branch
field :allow_domain, type: String, default: '' field :allow_domain #change from String to Array
field :installed_site_tokens, type: Array, default: [] field :installed_site_tokens, type: Array, default: []
mount_uploader :template_zip, AssetUploader 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_image_files, :allow_destroy => true
accepts_nested_attributes_for :template_psd_file, :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) def template_zip(origin_flag=false)
if self.git_url.blank? || self.git_branch.blank? || origin_flag if self.git_url.blank? || self.git_branch.blank? || origin_flag
super() super()