Twilio Ruby sending SMS - undefined method `messages'

拥有回忆 提交于 2019-12-12 18:11:21

问题


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.

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!


回答1:


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

If not, put that in and bundle

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

Here is another tutorial - https://www.twilio.com/blog/2012/02/adding-twilio-sms-messaging-to-your-rails-app.html




回答2:


Twilio evangelist here.

It may also be because we recently added the Messages resource and deprecated the SMS resource. So you may just need to update your gem to the latest version.

$ gem update twilio-ruby

Hope this helps!



来源:https://stackoverflow.com/questions/19611050/twilio-ruby-sending-sms-undefined-method-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!