From 64e14d42e277acf696268b32a3f8908885f06b2e Mon Sep 17 00:00:00 2001 From: Bernie Chiu Date: Wed, 11 Sep 2013 07:09:25 +0800 Subject: [PATCH] Allow ask_question transter --- .../ask/back_end/ask_replies_controller.rb | 22 ++++++++++++++----- .../ask/back_end/ask_requests_controller.rb | 21 ++++++++++++++++-- 2 files changed, 35 insertions(+), 8 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 02dd6190a..514e49b74 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 @@ -1,5 +1,5 @@ +# encoding: utf-8 class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController - include AdminHelper include OrbitControllerLib::DivisionForDisable @@ -33,9 +33,9 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id) end ## - send_request(@ask_question) + send_request(@ask_question) if params[:ask_reply][:status] == '轉介其他單位' ## - 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 def send_request(current_question) @@ -46,8 +46,7 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController uri = URI.parse("http://localhost:4000/panel/ask/back_end/ask_requests/auth_request") body = { - "a" => "123", - "b" => "456" + 'auth_token' => '3kjlfksjDFJ' } http = Net::HTTP.new(uri.host, uri.port) @@ -55,17 +54,28 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController request.set_form_data(body) response = http.request(request) # 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") http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri) body = { - 'title' => current_question.title + 'name' => current_question.name, + 'title' => current_question.title, + 'identity' => current_question.identity, + 'email' => current_question.email, + '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 end + + puts "Response #{response.code} #{response.message}: #{response.body}" # flash[:notice] = response.body # flash[:notice] = "Response #{response.code} #{response.message}: #{response.body}" end 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 e25b9636a..dca8d3739 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 @@ -1,10 +1,10 @@ +# encoding: utf-8 class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController include AdminHelper include OrbitControllerLib::DivisionForDisable def auth_request - params={'c' => '456' } render :json => "#{params}" end @@ -12,8 +12,25 @@ class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController # @ask_question = AskQuestion.all # x = @ask_question.count # params={'d' => x } - @transfered_question=AskQuestion.new(:title=>params[:title]) + + if !AskCategory.where(name: params['category']).any? + @ask_category = AskCategory.new(name: params['category'], key: params['category_key']) + @ask_category.save! + end + + category = AskCategory.where(name: params['category']) + + @transfered_question = AskQuestion.new( + name: params['name'], + identity: params['identity'], + email: params['email'], + phone: params['phone'], + tax: params['tax'], + title: params['title'], + content: params['content'], + ask_category_id: category.first.id) @transfered_question.save + render :json => "#{params}" end