【发布时间】:2014-06-19 01:58:58
【问题描述】:
第一次发帖(请客气,我已经研究过了!)
我是来自另一种语言的 Ruby 生态系统的新手,但这让我觉得很奇怪。我已将 twilio-ruby 库添加到我的 Gemfile,完成捆绑安装/尝试捆绑更新
捆绑显示 twilio-ruby ~/.rvm/gems/ruby-2.1.2/gems/twilio-ruby-3.11.5
但是,在尝试 任何 示例时,我收到以下错误。
Undefined method 'messages' for #<Twilio::REST::Client::Account:0x00000102cea740>
替代呼叫等。没有任何作用。甚至没有@client.account.sms.messages(遗留电话)。
我熟悉 pry 并且已经完成了 @client.pry 产生 self.account.methods.sort 并且这些方法/类成员根本不存在于模块中。
那么有什么作用呢? ruby test.rb 包含:
@client = Twilio::REST::Client.new '{{removed}}', '{{removed}}'
#@client.pry
p @client.account.messages.create(
:from => '+1XXX',
:to => '+1XXX',
:body => 'Hey there!'
)
如果我将相同的代码放在 application.rb 的顶部,在应用程序类声明之外它可以工作。
我还尝试过哪些其他地方?控制器、模型、在控制器/模型中导入和调用的独立类。似乎在 Rails 引导后它不起作用。我很困惑。
我很擅长调试,所以任何关于这个方向的提示都将不胜感激!
版本:Ruby 2.1.2、Rails 4.0.4、twilio-ruby 3.11.5
每次更改后,我都会重新启动 Rails 服务器。
更新
config/application.rb
require 'twilio-ruby'
@client = Twilio::REST::Client.new '{{removed}}', '{{removed}}'
#@client.pry
p @client.account.messages.create(
:from => '+',
:to => '+',
:body => 'Hey there!'
)
Bundler.require(:default, Rails.env)
#require 'twilio-ruby'
@client = Twilio::REST::Client.new '{{removed}}', '{{removed}}'
#@client.pry
p @client.account.messages.create(
:from => '+',
:to => '+',
:body => 'Hey there!'
)
在调用 bundler 之前调用 twilio-ruby 有效。
在调用 bundler 之后调用 twilio-ruby 不起作用。
【问题讨论】:
-
这绝对是奇怪的(对我来说不可复制)。如果您启动一个空的 Rails 项目,只添加
twilio-rubygem,这种情况还会发生吗? -
如果您取消注释
require 'twilio-ruby'在Bundler.requre调用之后是否有效? -
试试@client.account.sms.messages.create
标签: ruby-on-rails twilio