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 作为参数传递给 worker:

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 回答