Vote count:
0
I'm new to Rails and this is the first time I'm implementing an API into my app. I'm creating an app that allows users to schedule text messages (SMS) with twilio. I'm trying to pass in 'number' so that the user can input the number. I've gotten the app to work when I hard code a number in but I'm getting "A 'To' phone number is required." when I try to pass in an argument.
Here's the controller
class TextMessagesController < ApplicationController
def index
@message = TextMessage.all
end
def new
@message = TextMessage.new
end
def create
@active = 'messages'
@message = TextMessage.send_sms(params[:number], params[:message])
if @message.save
flash[:success] = "Text Message Sent."
redirect_to message_path
else
render 'home'
end
end
def text_message_params
params.require(:text_messages).permit(:number, :message)
end
end
Here's the Model
class TextMessage < ActiveRecord::Base
belongs_to :user
validates :message, length: { maximum: 160 }, presence: true
def self.send_sms(number, message)
twilio_account_sid = 'XXXXXX'
twilio_auth_token = 'XXXXXX'
twilio_number = 'XXXXXX'
@client = Twilio::REST::Client.new twilio_account_sid, twilio_auth_token
message = @client.account.sms.messages.create(
:from => "+1#{twilio_number}",
:to => "#{number}",
:body => "#{message}"
)
end
end
Anyone know where I'm making my mistake?
asked 1 min ago
A 'To' phone number is required-- Twilio-- Rails 4
Aucun commentaire:
Enregistrer un commentaire