Twilio Ruby发送短信 – 未定义的方法`消息’

我试图通过Twilio API从我的Rails应用程序发送短信。 我按照这里的说明( https://github.com/twilio/twilio-ruby )但我似乎无法想出这个。

这是我的rails控制器中的代码

require 'twilio-ruby' account_sid = '[I inserted account_sid here]' auth_token = '[I inserted auth_token here]' @client = Twilio::REST::Client.new(account_sid, auth_token) @client.account.messages.create( from: '+[number here]', to: '+[number here]', body: 'Hey there!' ) 

返回以下错误消息(出于简单隐私原因,省略号)

 NoMethodError .... undefined method `messages' for #<Twilio::REST::Account: .... 

任何帮助将不胜感激。 谢谢大家!

你有没有把’twilio-ruby’放在你的Gemfile中?

如果没有,请将其放入并捆绑

然后你可以从你的控制器中删除require’twilio-ruby’

这是另一个教程 – https://www.twilio.com/blog/2012/02/adding-twilio-sms-messaging-to-your-rails-app.html

Twilio福音传教士在这里。

这也可能是因为我们最近添加了Messages资源并弃用了SMS资源。 所以你可能只需要将你的gem更新到最新版本。

 $ gem update twilio-ruby 

希望这可以帮助!