Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How to send SMS Messages in Rails with Twilio Discussion

General • Asked by Chris Oliver

Great intro! We use Twilio to send SMS notifications to our users.

Question - I set up the Twilio client in an initializer. Is there any advantage to this over setting it up in the Twilio service object? I know global variables are generally frowned upon but they seem ok for clients like this.

# config/initializers/twilio.rb
require 'twilio-ruby'

Twilio.configure do |config|
  config.account_sid = ENV['TWILIO_ACCOUNT_SID']
  config.auth_token  = ENV['TWILIO_AUTH_TOKEN']

$twilio =

And thanks for the tip on the Google phone number gem. I've been using Twilio's Lookup REST API to validate phone numbers. It's likely more accurate but makes an API for every validation. Not so great. I think I'll be switching to phonelib soon 👍

That initializer works too. I'm just putting everything in the same class for now to keep it organized.

when i run this

  • rails credentials:edit --environment=development No $EDITOR to open file in. Assign one like this:

EDITOR="mate --wait" bin/rails credentials:edit

For editors that fork and exit immediately, it's important to pass a wait flag,
otherwise the credentials will be saved immediately with no chance to edit.

This is what I am using:
EDITOR=vim rails credentials:edit --environment=development

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.