diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb index 67ab8fa..317114d 100644 --- a/app/controllers/admin/asks_controller.rb +++ b/app/controllers/admin/asks_controller.rb @@ -155,13 +155,13 @@ class Admin::AsksController < OrbitAdminController @filter_fields = filter_fields(@categories) # 列表欄位 @table_fields = @ask_list_setting.default_fields.select{|f| @ask_setting.default_setting[f].nil? || @ask_setting.default_setting[f] } - if @category_id.present? + if !category_id.nil? ask_setting = AskCategorySetting.where(:category_id=>@category_id, :use_default.ne=>true).first if ask_setting.nil? ask_setting = AskSetting.first tmp = ask_setting.custom_fields.map{|k,v| ["default@#{k}", v]}.to_h else - tmp = ask_setting.custom_fields.map{|k,v| ["custom@#{k}", v]}.to_h + tmp = ask_setting.custom_fields.map{|k,v| ["custom@#{category_id}@#{k}", v]}.to_h end list_setting_custom_fields = @ask_list_setting.custom_fields else @@ -309,7 +309,7 @@ class Admin::AsksController < OrbitAdminController k = custom_fields.keys[i] rescue nil if !k.blank? v = custom_fields[k] rescue {} - text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question.custom_values[k],true,true) + text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question,true,true) text = text.gsub(format_text,text_tp.to_s) end when /custom\d+/ @@ -317,7 +317,7 @@ class Admin::AsksController < OrbitAdminController k = custom_fields.keys[i] rescue nil if !k.blank? v = custom_fields[k] rescue {} - text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question.custom_values[k],true) + text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question,true) text = text.gsub(format_text,text_tp.to_s) end end diff --git a/app/helpers/admin/asks_helper.rb b/app/helpers/admin/asks_helper.rb index d3db45f..d861616 100644 --- a/app/helpers/admin/asks_helper.rb +++ b/app/helpers/admin/asks_helper.rb @@ -207,7 +207,21 @@ module Admin::AsksHelper end end.join('  ') end - def show_on_front(k,v,value=nil,readonly=false,lock=false) + def show_on_front(k,v,object=nil,readonly=false,lock=false) + value = nil + if !object.nil? + value = object.custom_values[k] + if value.nil? + if k.start_with("default@") + value = object.custom_values[k.sub(/.*@/,'')] + elsif k.start_with("custom@") + category_id, k = k.scan(/custom@((?:(?!@).)*)@\w+/)[0][0] + if category_id==object.category_id.to_s + value = object.custom_values[k] + end + end + end + end field_name = "#{get_input_name_for_ask}[custom_values][#{k}]" begin case v['type'] diff --git a/app/views/admin/asks/_form.html.erb b/app/views/admin/asks/_form.html.erb index 675b103..6e376ca 100644 --- a/app/views/admin/asks/_form.html.erb +++ b/app/views/admin/asks/_form.html.erb @@ -108,7 +108,7 @@ "
- #{show_on_front(k,v,@ask_question.custom_values[k],true)} + #{show_on_front(k,v,@ask_question,true)}
" end.join.html_safe %> diff --git a/app/views/admin/asks/_index.html.erb b/app/views/admin/asks/_index.html.erb index 9dfa6eb..3e2e762 100644 --- a/app/views/admin/asks/_index.html.erb +++ b/app/views/admin/asks/_index.html.erb @@ -234,7 +234,7 @@ <% end %> <% @table_ext_fields.each do |f, v| %> - <%= show_on_front(f,v,b.custom_values[f],true) %> + <%= show_on_front(f,v,b,true) %> <% end %> diff --git a/app/views/asks/show.html.erb b/app/views/asks/show.html.erb index 151e941..c2ced5b 100644 --- a/app/views/asks/show.html.erb +++ b/app/views/asks/show.html.erb @@ -69,7 +69,7 @@ "
- #{show_on_front(k,v,ask.custom_values[k],true)} + #{show_on_front(k,v,ask,true)}
" end.join.html_safe %>