Twilio Ruby 发送短信 - 未定义的方法“消息" [英] Twilio Ruby sending SMS - undefined method `messages'

查看:24
本文介绍了Twilio Ruby 发送短信 - 未定义的方法“消息"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Twilio API 从我的 Rails 应用程序发送 SMS 消息.我正在按照此处的说明操作(https://github.com/twilio/twilio-ruby) 但我似乎无法弄清楚这一点.

I am trying to send an SMS message from my Rails app via the Twilio API. I'm following the instructions here (https://github.com/twilio/twilio-ruby) but I can't seem to figure this one out.

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

Here is the code in my rails controller

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!'
)

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

Returns the follow error message (ellipsis for simple privacy reasons)

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

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

Any help would be greatly appreciated. Thanks all!

推荐答案

你把'twilio-红宝石'在你的 Gemfile 中?

Have you put 'twilio-ruby' in your Gemfile?

如果没有,把它放进去捆绑

If not, put that in and bundle

然后你可以删除需要'twilio-ruby'来自您的控制器

Then you can remove require 'twilio-ruby' from your controller

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

这篇关于Twilio Ruby 发送短信 - 未定义的方法“消息"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆