1

我正在关注这个:教程

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,发现表是空的。
这是为什么?

编辑: 我收到此错误:

糟糕,出了点问题:[“授权无效”]

这是用户.rb:

class User < ActiveRecord::Base
  has_many :topics
  has_many :authorizations

  attr_accessible :email, :name
  validates :name, :email, :presence => true
end

这是授权.rb:

class Authorization < ActiveRecord::Base

  belongs_to :user
  validates :provider, :uid, :presence => true

  attr_accessible :provider, :uid
end
4

1 回答 1

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
于 2012-11-03T15:04:36.800 回答