未在生产中使用 Excon Rails 6.0.0 发送 API 请求

我遇到了一个问题,我使用 excon gem 的 POST 请求没有在生产中发送,但在开发中运行良好。在我的日志中,它显示 Processing ServiceFormsControlller#run_background_check 作为 HTML。我不知道为什么会发生这种情况……上周它运行良好。现在突然之间,没有从生产服务器发出请求......它显示了正在发生的操作,但 API 端点从未收到 POST。我将该网站作为白名单域添加到我的 CORS 配置中。这对改善结果没有任何作用。

service_forms_controller.rb

class ServiceFormsController < ApplicationController
 @service_form = ServiceForm.find(params[:id])
 @service_info = @service_form.info

 if @service_info.first_name.present? && @service_info.last_name.present? && @service_info.ssn.present? && @service_info.address.present? && @service_info.email.present?

@report_builder = GoodHire.new
if Rails.env.production?
 @report_builder.create_report_for_candidate(@service_info.first_name,@service_info.last_name,@service_info.ssn,@service_info.address,@service_info.email)
# other mandatory fields added to this call
end
  redirect_to service_forms_path,notice: "You've submitted the candidate for a background check"
  else
redirect_to service_forms_path,notice: "The candidate doesn't have all fields completed"
end

good_hire.rb

class GoodHire
  API_KEY_PROD = 'ZZzazzee'

include RestClient
include excon

def create_report_for_candidate(first_name,last_name,email,ssn,address,city,state,zip,work_histories =[].....,api_key = API_KEY_PROD)

begin
 excon.post("https://api.goodhire.com/v1/Report",body: {
  "Candidate": {
  "FirstName": "#{first_name}"
  ....
  ...  
},"Offer": {
  "Products": [
  "....ID"  
 ]
},"RequestOptions": {
  "SendPurchaseReceipt": true 
  }
}.to_json,headers: {"Content-Type" => "application/json","Authorization" => "ApiKey #{api_key}"})
 rescue excon::Errors => e
 puts "RESPONSE ERROR #{e.response}"
  end
end

服务器开发日志

Started POST "/service_forms/7/run_candidate_bckground_check?id=7" for 127.0.0.1
Processing by ServiceFormsController#run_candidate_background_check as HTML
Parameters: {"authenticity_token" => "zregegegergergergegegege","id" => "7","service_form_id"=> "7"}

app/controllers/service_forms_controller.rb: in `run_candidate_background_check'
Redirected to https://127.0.0.1:3000/service_forms 
Completed 302 Found in 4359ms

Started GET "/service_forms" for 127.0.0.1

initate_background_check.html.erb

<body>
 <%= button_to service_form_run_candidate_background_check(service_form_id: @service_form.id,id: @service_form.id),method: :post,class: 'bttn-simple bttn-sm bttn-primary'do %>
  Start Background Check
<% end %>
</body>
zdx1222 回答:未在生产中使用 Excon Rails 6.0.0 发送 API 请求

API 验证导致 API 请求失败

本文链接:https://www.f2er.com/1042730.html

大家都在问