我正在关注此事:tutorial
user = User.new :name => auth_hash["user_info"]["name"], :email => auth_hash["user_info"]["email"]
user.authorizations.build :provider => auth_hash["provider"], :uid => auth_hash["uid"]
user.save
render :text => "Hi #{user.name}! You've signed up."
我正在浏览数据库并检查表格authorization
,并且表格中的表格是空的
那是为什么?
修改 我收到这个错误:
哎呀,出了点问题:[“授权无效”]
这是user.rb:
class User < ActiveRecord::Base
has_many :topics
has_many :authorizations
attr_accessible :email, :name
validates :name, :email, :presence => true
end
这是authorization.rb:
class Authorization < ActiveRecord::Base
belongs_to :user
validates :provider, :uid, :presence => true
attr_accessible :provider, :uid
end
答案 0 :(得分:1)
始终检查返回值:
...
if user.save
render :text => "Hi #{user.name}! You've signed up."
else
# do something with the errors, e.g.:
render :text => "Oops, something went wrong: #{user.errors.full_messages}"
end