Usercontroller中的Twilio异常#create

时间:2014-02-01 19:44:01

标签: ruby-on-rails-4 twilio

我正在使用twilio在注册的手机号码上发送和接收短信。我的问题是我的用户没有注册。这是我的代码

Userscontroller

    class UsersController < ApplicationController

  def new
   @user = User.new
 end

 def create
   @user = User.new(params[:user])
     if @user.save
       render text: "Thank you! You will receive an SMS shortly with verification instructions."

    # Instantiate a Twilio client
      client = Twilio::REST::Client.new(TWILIO_CONFIG['sid'], TWILIO_CONFIG['token'])

    # Create and send an SMS message
    client.account.sms.messages.create(
      from: TWILIO_CONFIG['from'],
       to: @user.phone,
        body: "Thanks for signing up. To verify your account, please reply HELLO to this message."
    )
    else
       render :new
   end
 end

end

我是否需要提供任何其他代码。如果您愿意,请告诉我。 任何人都可以帮我这个代码。 我在控制器中做错了什么 谢谢

1 个答案:

答案 0 :(得分:0)

看起来你错过了=>并让:出错了。

尝试:

client.account.messages.create(
  :from => TWILIO_CONFIG['from'],
  :to => @user.phone,
  :body => "Thanks for signing up. To verify your account, please reply HELLO to this message."
)