public
Created

Adding SMS capabilities to your Rails Application

  • Download Gist
users_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class UsersController < ApplicationController
 
def new
@user = User.new
end
 
def create
@user = User.new(params[:user])
if @user.save
render text: "Thank you! You will receive an SMS shortly with verification instructions."
# Instantiate a Twilio client
client = Twilio::REST::Client.new(TWILIO_CONFIG['sid'], TWILIO_CONFIG['token'])
# Create and send an SMS message
client.account.sms.messages.create(
from: TWILIO_CONFIG['from'],
to: @user.phone,
body: "Thanks for signing up. To verify your account, please reply HELLO to this message."
)
else
render :new
end
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.