2013-09-24 98 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

相關問題