add transfered_category if not exist. change transfered reply's status to 待處理(轉). showing request code if error.

This commit is contained in:
thomaschen 2013-09-11 12:19:44 +08:00 committed by chris
parent 64e14d42e2
commit 1237a111ca
2 changed files with 16 additions and 18 deletions

View File

@ -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}"

View File

@ -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}"