gpt4 book ai didi

ruby-on-rails - 未初始化的常量 Twilio::Rest Rails

转载 作者:太空宇宙 更新时间:2023-11-03 18:14:33 25 4
gpt4 key购买 nike

我一直收到 uninitialized constant Twilio::Rest 错误,无法弄清楚我做错了什么。我的代码如下。

表盘型号

require 'twilio-ruby'
class Dial < ActiveRecord::Base
before_create :send_call

private

def send_call
#begin
account_sid = 'sid'
account_auth_token = 'auth'
caller = '+14693514939'
numbers = Number.find_by_sql('select phone from numbers')

@client = ::Twilio::Rest::Client.new account_sid, account_auth_token

numbers.each do |dial|

@client.account.calls.create(
:from => caller,
:to => dial,
:url => 'http://twimlets.com/echo?Twiml=hello%20this%20is%20a%20test%20call%20please%20hang%20up&')
end
#rescue
#false
#end
end
end

我的表盘 View

<%= button_to "Call", action: "create" %>

有什么想法吗?

最佳答案

可能是第一个::扔掉它。尝试:

@client = Twilio::REST::Client.new account_sid, account_auth_token

代替

@client = ::Twilio::Rest::Client.new account_sid, account_auth_token

示例:https://github.com/twilio/twilio-ruby/blob/master/examples/examples.rb

另见 https://github.com/twilio/twilio-ruby/blob/master/lib/twilio-ruby/rest/client.rb - 看起来 REST 应该大写。

关于ruby-on-rails - 未初始化的常量 Twilio::Rest Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28309431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com