From 164357aedf7e8fc3e0ae22c2ef3620617e0db9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 25 May 2022 14:19:05 +0800 Subject: [PATCH] fix error --- app/models/ask_category_setting.rb | 3 +++ app/models/ask_setting.rb | 5 +++++ lib/ask/engine.rb | 13 +++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/models/ask_category_setting.rb b/app/models/ask_category_setting.rb index 6ac6fd5..2f08f5a 100644 --- a/app/models/ask_category_setting.rb +++ b/app/models/ask_category_setting.rb @@ -41,4 +41,7 @@ class AskCategorySetting field :usage_rule field :category_id 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 diff --git a/app/models/ask_setting.rb b/app/models/ask_setting.rb index 3747fd3..a750e66 100644 --- a/app/models/ask_setting.rb +++ b/app/models/ask_setting.rb @@ -19,6 +19,11 @@ class AskSetting self.save 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 tmp = super tmp.select{|k,v| v['delete'] != true} diff --git a/lib/ask/engine.rb b/lib/ask/engine.rb index d2024c9..ff8c898 100644 --- a/lib/ask/engine.rb +++ b/lib/ask/engine.rb @@ -26,15 +26,20 @@ module Ask end begin 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__) if defined?(AskSetting) - if AskSetting.first.nil? - AskSetting.create() + ask_setting = AskSetting.first + if ask_setting.nil? + ask_setting = AskSetting.create() elsif AskSetting.count > 1 - AskSetting.all[1..-1].each do |ask_setting| - ask_setting.destroy + AskSetting.all[1..-1].each do |a| + a.destroy 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 if defined?(AskSettingIndex) if AskSettingIndex.first.nil?