ruby on rails - Twilio api asking for 'FROM' number each time -
using twilio ruby gem , i'm passing params 'to' , 'body' form view helper within :message , defaulted , set 'from' number within code, each time run , i'm getting:
twilio::rest::requesterror in messagescontroller#create
a 'from' phone number required.
class messagescontroller < applicationcontroller (other methods in here well) def create user = user.find(params[:user_id]) @account_sid = '******' @auth_token = '**********' = '+1347*****' body = params[:message][:body] = params[:message][:to] = '+1347******' @client = twilio::rest::client.new(@account_sid, @auth_token) # sends sms message @client.account.sms.messages.create(body => :body, => :from, => :to) # saves form message in model message user.messages.create(body => :body, => :from, => :to) redirect_to '/' end
your hashes seem backwards
user.messages.create(body => :body, => :from, => :to)
should read
user.messages.create(:body => body, :from => from, :to => to)
in examples setting key value of body, from, , to, symbols body, from, to.
Comments
Post a Comment