0

次のエラーが表示されます。

Error message: undefined local variable or method `call_alert_path' for #<RoadrunnerTwilioAlert:0x007f34401bbd10>

call_alert_pathただし、ルートで適切に定義されているように感じます。これは、私のテストが合格したという事実によって裏付けられています。テスト モードと本番の主な違いは、本番では、呼び出すメソッドがcall_alert_path非同期ジョブにあることです。call_alert_pathおそらくそれはそれを台無しにしています...とにかく、それ以外の場合は正しく定義されており、記述されたコードに問題がないことをコミュニティに確認したいだけです。

コントローラーコード:

# calls async job in production
if Rails.env == "production"
  RoadrunnerTwilioAlert.new.async.perform(params[:rentalrequest_id])
else
  @alert = twilio_client.account.calls.create(
    from: ENV["Twilio_Verified_Phone"],
    to: ENV["Roadrunner_Phone"],
    url: call_alert_path,
    method: 'post'
  )
  @request.update_attributes(twilio_alert: "call")
end

非同期ジョブ コード:

def perform(rentalrequest_id)
  @request = Request.find(id)
  @alert = twilio_client.account.calls.create(
    from: ENV["Twilio_Verified_Phone"],
    to: ENV["Roadrunner_Phone"],
    url: call_alert_path,
    method: 'post'
  )
  @request.update_attributes(twilio_alert: "call")
end

ルート:

match '/twilio/call_alert', to: 'twilio#call_alert', via: :post, as: "call_alert"
4

1 に答える 1

2

URL ヘルパーはワーカーでは使用できません。代わりに、URL を引数としてワーカーに渡します。

def perform(rentalrequest_id, url)
  @request = Request.find(id)
  @alert = twilio_client.account.calls.create(
    from: ENV["Twilio_Verified_Phone"],
    to: ENV["Roadrunner_Phone"],
    url: url,
    method: 'post'
  )
  @request.update_attributes(twilio_alert: "call")
end
于 2015-02-19T00:18:46.753 に答える