這是我的會話控制器。我改變了this question中的一行代碼,我只是有點不確定爲什麼它是這樣的。當從數據庫中獲取用戶時,在用戶和用戶之間區分用戶和用戶
我已經找到了類的定義,並做了很多研究,試圖找出爲什麼unless user.present?
不是一個資本美國例如。 unless User.present?
如果它是用戶類,那麼它應該是用戶在數據庫中搜索爲User.find_by
是。
是否首先查看以小寫形式讀取User的數據庫。
我這樣說是因爲它之前的代碼行也使用user = User.from_omniauth(env["omniauth.auth"])
並且User也是大寫的,所以如何區分兩個User類的代碼?
def create
user = User.from_omniauth(env["omniauth.auth"])
unless user.present?
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
log_in user
redirect_to user_url(user)
# Log the user in and redirect to the user's show page.
else
# Create an error message.
flash.now[:danger] = 'Invalid email/password combination'
render 'new'
end
else
log_in user
redirect_to user_url(user)
end
end
啊好吧,我現在完全明白了。感謝您的幫助,並編輯我的文章:)我認爲通過變量你的意思是常量,如果他們是大寫的反正。 –