Twilio api每次都要求'FROM'号码

时间:2013-09-24 17:14:44

标签: ruby-on-rails api twilio

使用Twilio Ruby gem并且我从表单视图帮助器中传递'to'和'body'的params:message并且我默认并在代码中设置'from'数字,但每次我运行它,我收到了:

在MessagesController中创建的Twilio :: REST :: RequestError

需要“来自”电话号码。

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

1 个答案:

答案 0 :(得分:3)

你的哈希似乎都倒退了

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

应该阅读

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

在您的示例中,您要设置一个键,其值为body,from和to,符号body,from,to。