2

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!

Kevin Shen
  • 48
  • 5

2 Answers2

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!

xmjw
  • 3,154
  • 21
  • 29
  • I have [a similar problem](http://stackoverflow.com/questions/26076867/twilio-ruby-sms-undefined-method-empty) but none of the solutions offered here worked. Can you, perhaps, give any advice? – Nick Sep 27 '14 at 21:05
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

strivedi183
  • 4,749
  • 2
  • 31
  • 38
  • Wow thank you! It worked when I removed require 'twilio-ruby' from the controller like you suggested. How did that solve my problem? For others with the same problem - if this doesn't work for you, I also restarted rails server. Perhaps that might be part of the solution. – Kevin Shen Oct 26 '13 at 20:55