fix error

This commit is contained in:
chiu 2021-02-23 23:55:50 +08:00
parent 10590cf08d
commit 858f3f8b85
1 changed files with 19 additions and 15 deletions

View File

@ -161,15 +161,19 @@ class Admin::AsksController < OrbitAdminController
custom_exist_nums = []
custom_exists = text.scan(/{custom\d+}/)
custom_exists.each do |custom_exist|
k = custom_exist[6...-1]
k = custom_exist[6...-1].to_i - 1
custom_exist_nums << k
end
customs.each do |custom|
tmp = custom_fields.keys.select{|key| custom_exist_nums.exclude? key}.collect do |k|
tp = custom.gsub(/{custom}/,"{custom#{k}}")
tp = tp.gsub(/{custom_title}/,"{custom#{k}_title}")
tp
end.join
tmp = custom_fields.keys.collect.with_index do |k,i|
if custom_exist_nums.exclude?(i)
tp = custom.gsub(/{custom}/,"{custom#{i+1}}")
tp = tp.gsub(/{custom_title}/,"{custom#{i+1}_title}")
tp
else
nil
end
end.compact.join
text = text.gsub(custom,tmp)
end
end
@ -178,10 +182,10 @@ class Admin::AsksController < OrbitAdminController
if format_text[-7...-1] == '_title'
case format_text[1...-7]
when /custom\d+/
i = format_text.scan(/\d+/)[0]
k = custom_fields.keys.index(i) rescue nil
i = format_text.scan(/\d+/)[0].to_i - 1
k = custom_fields.keys[i] rescue nil
if !k.blank?
text_tp = custom_fields.values[k]['field'][I18n.locale] rescue ''
text_tp = custom_fields[k]['field'][I18n.locale] rescue ''
text = text.gsub(format_text,text_tp)
end
when 'title'
@ -223,18 +227,18 @@ class Admin::AsksController < OrbitAdminController
text = text.gsub(format_text,I18n.t('ask,no'))
end
when /custom\d+\|format/
i = format_text.scan(/\d+/)[0]
k = custom_fields.keys.index(i) rescue nil
i = format_text.scan(/\d+/)[0].to_i - 1
k = custom_fields.keys[i] rescue nil
if !k.blank?
v = custom_fields.values[k] rescue {}
v = custom_fields[k] rescue {}
text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question.custom_values[k],true,true)
text = text.gsub(format_text,text_tp.to_s)
end
when /custom\d+/
i = format_text.scan(/\d+/)[0]
k = custom_fields.keys.index(i) rescue nil
i = format_text.scan(/\d+/)[0].to_i - 1
k = custom_fields.keys[i] rescue nil
if !k.blank?
v = custom_fields.values[k] rescue {}
v = custom_fields[k] rescue {}
text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question.custom_values[k],true)
text = text.gsub(format_text,text_tp.to_s)
end