Hi, 今天看到一段代码:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:digitalocean]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
end
end
end
在 method from_omniauth 中,调用 where 时前面没有调用它的 object,正常写法应该是 User.where(...) 吧,这是 Rails 的一种默认方式吗?