【问题标题】:Twilio Ruby sending SMS - undefined method `messages'Twilio Ruby 发送短信 - 未定义的方法“消息”
【发布时间】:2013-10-26 19:40:55
【问题描述】:

我正在尝试通过 Twilio API 从我的 Rails 应用程序发送 SMS 消息。我正在按照此处的说明进行操作 (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: ....

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

【问题讨论】:

    标签: ruby-on-rails ruby sms twilio


    【解决方案1】:

    Twilio 布道者在这里。

    也可能是因为我们最近添加了 Messages 资源并弃用了 SMS 资源。因此,您可能只需将 gem 更新到最新版本。

    $ gem update twilio-ruby
    

    希望这会有所帮助!

    【讨论】:

    • 我有a similar problem,但这里提供的解决方案都不起作用。你能不能给点建议?
    【解决方案2】:

    你放了吗 'twilio-ruby' 在您的 Gemfile 中?

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

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

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

    【讨论】:

    • 哇,谢谢!当我按照您的建议从控制器中删除 require 'twilio-ruby' 时,它起作用了。那是如何解决我的问题的?对于其他有同样问题的人——如果这对你不起作用,我还重新启动了 rails 服务器。也许这可能是解决方案的一部分。
    猜你喜欢
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多