2013-09-24 49 views
0

使用Twilio Ruby gem,我从表单视图助手内部传递'to'和'body'的参数:message,我默认并设置'from'代码中的数字,但每个我运行它时,我得到:twilio api每次都要求'FROM'号码

Twilio :: REST :: RequestError在MessagesController#创建

A“从”电话号码是必需的。

class MessagesController < ApplicationController 

(other methods in here as well) 

def create 


user = User.find(params[:user_id]) 
    @account_sid = '******' 
    @auth_token = '**********' 
    from = '+1347*****' 
    body = params[:message][:body] 
    to = params[:message][:to] 
    from = '+1347******' 
    @client = Twilio::REST::Client.new(@account_sid, @auth_token) 

    # this sends the sms message 
    @client.account.sms.messages.create(body => :body, from => :from, to => :to) 

    # this saves the form message in the model Message 
    user.messages.create(body => :body, from => :from, to => :to) 

    redirect_to '/' 
end 
+0

如果遇到任何其他问题,你会得到意想不到的结果,你可以使用它来检查你的API调用:https://www.runscope.com/docs/code-examples/twilio(是的无耻的插件我知道:) –

回答

3

您的哈希似乎都向后

user.messages.create(body => :body, from => :from, to => :to) 

应该读

user.messages.create(:body => body, :from => from, :to => to) 
在你的例子要设置与主体价值的关键,从,并以符号身体

, 从到。

+0

就是这样,谢谢! – Anthony

相关问题