devise rails current_user vs user_signed_in? [英] devise rails current_user vs user_signed_in?

查看:154
本文介绍了devise rails current_user vs user_signed_in?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Devise on Rails 4.1
我的问题是关于帮助者以及它们与会话的关系。
current_user:告诉您用户是否有用户会话可用。
user_signed_in:告诉你用户是否经过身份验证。



我不明白如果user_signed_in可以有一个current_user,是错误的?



两种方法有什么区别,它与会话如何相关。



谢谢。
Richard Madson

解决方案

current_user 方法返回当前登录的用户,而 user_signed_in?方法用于验证是否有用户登录并返回true或false。如果 user_signed_in?为false,那么 current_user 方法将返回nil。



https://github.com/plataformatec/devise#controller-filters-and-helpers


I am using Devise on Rails 4.1 My question is regarding the helpers and how they relate to sessions. current_user : tells you if there is a user session available for the user. user_signed_in: tells you if the user is authenticated.

I cannot understand how a there can be a current_user if the user_signed_in? is false?

What is the difference between the two methods, and how does it relate to sessions.

THanks. Richard Madson

解决方案

current_user method returns current signed-in user, while user_signed_in? method is used to verify if any user is signed in and returns true or false. if user_signed_in? is false then current_user method will return nil.

https://github.com/plataformatec/devise#controller-filters-and-helpers

这篇关于devise rails current_user vs user_signed_in?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆