0
*********更新:我只是試圖重新啓動Rails服務器,它似乎已經奏效!Rails的添加Twilio子賬戶:未初始化的常數用戶:: Twilio
我已經構建了一個基於Michael Hartl的Rails教程的基本認證系統,現在我想要做的是在用戶註冊時使用Twilio的API創建Twilio子帳戶。
https://www.twilio.com/docs/api/rest/subaccounts
我如何創建它的想法是用戶模型中使用before_save,並有twilio創建身份驗證令牌和帳戶SID爲子帳戶。問題是,當我點擊提交,我得到 -
NameError in UsersController#create
uninitialized constant User::Twilio
Rails.root: C:/Sites/dentist
Application Trace | Framework Trace | Full Trace
app/models/user.rb:45:in `create_twilio_subaccount'
app/controllers/users_controller.rb:13:in `create'
這裏是我的當前用戶型號:
#Twilio authentication credentials
ACCOUNT_SID = '####removed for stackoverflow#####'
ACCOUNT_TOKEN = '####removed for stackoverflow#####'
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# password_digest :string(255)
# remember_token :string(255)
# twilio_account_sid :string(255)
# twilio_auth_token :string(255)
#
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = email.downcase }
before_save :create_remember_token
before_save :create_twilio_subaccount
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: true
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
def create_twilio_subaccount
@client = Twilio::REST::Client.new(ACCOUNT_SID, ACCOUNT_TOKEN)
@subaccount = @client.accounts.create({:FriendlyName => self[:email]})
self.twilio_account_sid = @subaccount.sid
self.twilio_auth_token = @subaccount.auth_token
end
end
上我應該做內部create_twilio_subaccount這將是任何幫助,不勝感激它。基於remember_token的工作原理,這只是我的猜測。讓我知道如果我做的事情完全古怪!