From ee69221b8f4ab848e787bab85dd8e73a50b1c095 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Wed, 4 Sep 2024 00:00:52 +0800 Subject: [PATCH] Fix bug. --- app/controllers/asks_controller.rb | 7 ++++++- app/models/ask_category_setting.rb | 3 ++- app/models/ask_setting.rb | 14 ++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb index dd1f291..4bd170c 100644 --- a/app/controllers/asks_controller.rb +++ b/app/controllers/asks_controller.rb @@ -198,6 +198,11 @@ class AsksController < ApplicationController temp_params = create_params all_to_save = [] ask_setting = AskCategorySetting.enabled.where(category_id: params['ask_question']['category_id']).first + override_sort_number = nil + if ask_setting.use_default + override_sort_number = ask_setting.default_sort_number + ask_setting = nil + end if ask_setting.nil? ask_setting = AskSetting.first ask_setting = AskSetting.create() if ask_setting.nil? @@ -264,7 +269,7 @@ class AsksController < ApplicationController end end if (email_regex ? ::Regexp.new(email_regex).match(temp_params["mail"].to_s) : true) && flag - @disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting, true, nil, true) + @disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting, true, override_sort_number, true) @usage_rule = ask_setting.usage_rule if temp_params['mail'].blank? temp_params = temp_params.merge({ diff --git a/app/models/ask_category_setting.rb b/app/models/ask_category_setting.rb index 15402e4..8b4cc25 100644 --- a/app/models/ask_category_setting.rb +++ b/app/models/ask_category_setting.rb @@ -165,4 +165,5 @@ class AskCategorySetting field :reject_customs, type: Array, default: [] #From AskSetting field :agree_customs, type: Array, default: [] #From AskSetting scope :enabled, ->{any_of([{:use_default.ne=>true}, {:use_default=>true, :default_sort_number.nin=>[nil, {}]}])} -end \ No newline at end of file + scope :custom_enabled, ->{where({:use_default.ne=>true})} +end diff --git a/app/models/ask_setting.rb b/app/models/ask_setting.rb index 695a91d..27f4fa1 100644 --- a/app/models/ask_setting.rb +++ b/app/models/ask_setting.rb @@ -146,7 +146,8 @@ class AskSetting ask_setting = nil if cat_is_record ask_setting = cat - is_cat_record = !(override_sort_number.nil?) || cat.class == AskCategorySetting + is_cat_record = (cat.class == AskCategorySetting) + is_cat_record2 = is_cat_record || !(override_sort_number.nil?) else if cat.present? ask_setting = AskCategorySetting.enabled.where(:category_id=>cat).first @@ -203,10 +204,10 @@ class AskSetting disp_fields_infos[tmp_k] = sort_number[tmp_k] end ask_category_settings = [] - if is_cat_record + if is_cat_record2 ask_category_settings = [] else - ask_category_settings = AskCategorySetting.enabled.to_a + ask_category_settings = AskCategorySetting.custom_enabled.to_a end ask_category_settings.each do |c| category = Category.find(c.category_id) rescue nil @@ -246,7 +247,8 @@ class AskSetting ask_setting = nil if cat_is_record ask_setting = cat - is_cat_record = !(override_sort_number.nil?) || cat.class == AskCategorySetting + is_cat_record = (cat.class == AskCategorySetting) + is_cat_record2 = is_cat_record || !(override_sort_number.nil?) else if cat.present? ask_setting = AskCategorySetting.enabled.where(:category_id=>cat).first @@ -311,10 +313,10 @@ class AskSetting disp_fields_infos[tmp_k] = {"trans"=>trans,"sort_number"=>sort_number[tmp_k],"key"=>k,"type"=>v["type"],"options"=>v["options"],"instructions"=>v["instructions"]} end ask_category_settings = [] - if is_cat_record + if is_cat_record2 ask_category_settings = [] else - ask_category_settings = AskCategorySetting.enabled.to_a + ask_category_settings = AskCategorySetting.custom_enabled.to_a end ask_category_settings.each do |c| category = Category.find(c.category_id) rescue nil