Allow ask_question transter

This commit is contained in:
Bernie Chiu 2013-09-11 07:09:25 +08:00 committed by chris
parent cc7a4ffb6d
commit 64e14d42e2
2 changed files with 35 additions and 8 deletions

View File

@ -1,5 +1,5 @@
# encoding: utf-8
class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
include AdminHelper include AdminHelper
include OrbitControllerLib::DivisionForDisable include OrbitControllerLib::DivisionForDisable
@ -33,9 +33,9 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id) Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id)
end 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 end
def send_request(current_question) 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") uri = URI.parse("http://localhost:4000/panel/ask/back_end/ask_requests/auth_request")
body = { body = {
"a" => "123", 'auth_token' => '3kjlfksjDFJ'
"b" => "456"
} }
http = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port)
@ -55,17 +54,28 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
request.set_form_data(body) request.set_form_data(body)
response = http.request(request) response = http.request(request)
# puts "Response #{response.code} #{response.message}: #{response.body}" # puts "Response #{response.code} #{response.message}: #{response.body}"
if response.code == "200" if response.code == "200"
uri = URI.parse("http://localhost:4000/panel/ask/back_end/ask_requests/transfer_request") uri = URI.parse("http://localhost:4000/panel/ask/back_end/ask_requests/transfer_request")
http = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri) request = Net::HTTP::Post.new(uri.request_uri)
body = { 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) request.set_form_data(body)
response = http.request(request) response = http.request(request)
flash[:notice] = response.body flash[:notice] = response.body
end end
puts "Response #{response.code} #{response.message}: #{response.body}"
# flash[:notice] = response.body # flash[:notice] = response.body
# flash[:notice] = "Response #{response.code} #{response.message}: #{response.body}" # flash[:notice] = "Response #{response.code} #{response.message}: #{response.body}"
end end

View File

@ -1,10 +1,10 @@
# encoding: utf-8
class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController
include AdminHelper include AdminHelper
include OrbitControllerLib::DivisionForDisable include OrbitControllerLib::DivisionForDisable
def auth_request def auth_request
params={'c' => '456' }
render :json => "#{params}" render :json => "#{params}"
end end
@ -12,8 +12,25 @@ class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController
# @ask_question = AskQuestion.all # @ask_question = AskQuestion.all
# x = @ask_question.count # x = @ask_question.count
# params={'d' => x } # 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 @transfered_question.save
render :json => "#{params}" render :json => "#{params}"
end end