我有这个工作,但不知怎的,它现在已经坏了。几个小时在我身上敲我的头......我已经看过Ryan Bates视频10倍了。一切似乎都正确..为什么我不能在用户模型中保存电子邮件地址???
我在user.rb中有这个
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable, :omniauth_providers => [:facebook, :soundcloud]
attr_accessor :email, :password, :password_confirmation, :remember_me, :username, :first_name, :last_name, :city, :country
def self.from_omniauth(auth, current_user)
where(:provider => auth.provider, :uid => auth.uid.to_s).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.name
user.avatar = auth.info.image
user.email = auth.info.email
user.oauth_token = auth.credentials.token
user.oauth_secret = auth.credentials.secret
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
auth.provider == "soundcloud" ? user.save(:validate => false) : user.save
end
端
答案 0 :(得分:0)
因此,现在只需注释掉attr_accessor行,我就可以保存所有用户数据,包括电子邮件地址。任何人都想知道为什么会这样运作?