From 1237a111cabec11683211495cc754bf619d4ce7f Mon Sep 17 00:00:00 2001 From: thomaschen <99703040@nccu.edu.tw> Date: Wed, 11 Sep 2013 12:19:44 +0800 Subject: [PATCH] =?UTF-8?q?add=20transfered=5Fcategory=20if=20not=20exist.?= =?UTF-8?q?=20change=20transfered=20reply's=20status=20to=20=E5=BE=85?= =?UTF-8?q?=E8=99=95=E7=90=86(=E8=BD=89).=20=20showing=20request=20code=20?= =?UTF-8?q?if=20error.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ask/back_end/ask_replies_controller.rb | 22 +++++++++---------- .../ask/back_end/ask_requests_controller.rb | 12 +++++----- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb index 514e49b74..8b1b66db8 100644 --- a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb +++ b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb @@ -17,11 +17,6 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController if @ask_question.ask_reply.send_email? Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id) end - ## - ##if status == "..." - ##send_request - ##------------------- - # redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success') redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success') end @@ -33,12 +28,12 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id) end ## - send_request(@ask_question) if params[:ask_reply][:status] == '轉介其他單位' + send_request(@ask_question, @ask_reply) if params[:ask_reply][:status] == '轉介其他單位' ## redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success') end - def send_request(current_question) + def send_request(current_question, current_reply) require 'net/http' require 'uri' require 'json' @@ -53,7 +48,7 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController request = Net::HTTP::Post.new(uri.request_uri) request.set_form_data(body) response = http.request(request) - # puts "Response #{response.code} #{response.message}: #{response.body}" + puts "Response #{response.code} #{response.message}: #{response.body}" if response.code == "200" uri = URI.parse("http://localhost:4000/panel/ask/back_end/ask_requests/transfer_request") @@ -67,12 +62,17 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController 'phone' => current_question.phone, 'tax' => current_question.tax, 'content' => current_question.content, - 'category' => current_question.ask_category.name, - 'category_key' => current_question.ask_category.key } request.set_form_data(body) response = http.request(request) - flash[:notice] = response.body + + if response.code != "200" + new_status = "轉介其他單位" + "(" + response.code + ")" + current_reply.update_attributes(status: new_status) + else + new_status = "轉介其他單位" + "(" + "succes!" + ")" + current_reply.update_attributes(status: new_status) + end end puts "Response #{response.code} #{response.message}: #{response.body}" diff --git a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb index dca8d3739..eff47c5ff 100644 --- a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb +++ b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb @@ -9,16 +9,12 @@ class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController end def transfer_request - # @ask_question = AskQuestion.all - # x = @ask_question.count - # params={'d' => x } - if !AskCategory.where(name: params['category']).any? - @ask_category = AskCategory.new(name: params['category'], key: params['category_key']) + if !AskCategory.where(key: "transfered_question").any? + @ask_category = AskCategory.new(name: "transfered_question", key: "transfered_question") @ask_category.save! end - - category = AskCategory.where(name: params['category']) + category = AskCategory.where(key: "transfered_question") @transfered_question = AskQuestion.new( name: params['name'], @@ -29,6 +25,8 @@ class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController title: params['title'], content: params['content'], ask_category_id: category.first.id) + @transfered_question.ask_reply = AskReply.new + @transfered_question.ask_reply.update_attributes(status: "待處理(轉)") @transfered_question.save render :json => "#{params}"