Created
June 22, 2012 07:05
-
-
Save tjackiw/2970902 to your computer and use it in GitHub Desktop.
Adding SMS capabilities to your Rails Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment