0
********* 업데이트 : 레일즈 서버를 다시 시작해 보았습니다.레일즈 Twilio 서브 계정 추가 : 초기화되지 않은 상수 User :: Twilio
저는 레일스에 대한 Michael Hartl의 튜토리얼에 따라 기본 인증 시스템을 구축했습니다. 이제 사용자가 등록 할 때 Twilio의 API를 사용하여 Twilio Sub Account를 만드는 것이 좋습니다. 를 작성하는 방법에 대한
https://www.twilio.com/docs/api/rest/subaccounts
내 생각은 사용자 모델에 before_save를 사용했다, 및 서브 계정의 인증 토큰 및 계정 시드를 만들 twilio 있습니다.
#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 내부에해야 할 일에 어떤 도움을 크게 그것을 감사 :
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'
가 여기 내 현재 사용자의 모델이다 - 문제는 내가 쳤을 때 내가 얻을 제출하는 것이있다. 이것은 remember_token이 어떻게 작동했는지에 기초하여 그것을 수행하는 방법에 대한 나의 추측입니다. 내가 완전히 이상한 짓을하고 있다면 알려줘!