我看到以下错误:
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"