fix error

This commit is contained in:
邱博亞 2022-05-25 14:19:05 +08:00
parent 52358bb533
commit 164357aedf
3 changed files with 17 additions and 4 deletions

View File

@ -41,4 +41,7 @@ class AskCategorySetting
field :usage_rule field :usage_rule
field :category_id field :category_id
field :title_layout, type: Integer field :title_layout, type: Integer
field :email_regex_enable, type: Boolean, default: false
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
end end

View File

@ -19,6 +19,11 @@ class AskSetting
self.save self.save
end end
end end
after_save do
if self.email_regex_enable_changed? || self.email_regex_changed?
AskCategorySetting.all.update_all(email_regex_enable: self.email_regex_enable,email_regex: self.email_regex)
end
end
def custom_fields def custom_fields
tmp = super tmp = super
tmp.select{|k,v| v['delete'] != true} tmp.select{|k,v| v['delete'] != true}

View File

@ -26,15 +26,20 @@ module Ask
end end
begin begin
require File.expand_path('../../../app/models/ask_setting', __FILE__) require File.expand_path('../../../app/models/ask_setting', __FILE__)
require File.expand_path('../../../app/models/ask_category_setting', __FILE__)
require File.expand_path('../../../app/models/ask_setting_index', __FILE__) require File.expand_path('../../../app/models/ask_setting_index', __FILE__)
if defined?(AskSetting) if defined?(AskSetting)
if AskSetting.first.nil? ask_setting = AskSetting.first
AskSetting.create() if ask_setting.nil?
ask_setting = AskSetting.create()
elsif AskSetting.count > 1 elsif AskSetting.count > 1
AskSetting.all[1..-1].each do |ask_setting| AskSetting.all[1..-1].each do |a|
ask_setting.destroy a.destroy
end end
end end
if ask_setting.email_regex_enable
AskCategorySetting.all.update_all(email_regex_enable: ask_setting.email_regex_enable,email_regex: ask_setting.email_regex)
end
end end
if defined?(AskSettingIndex) if defined?(AskSettingIndex)
if AskSettingIndex.first.nil? if AskSettingIndex.first.nil?