What is the difference between current_user.present and if user_signed_in?

Working on the design and wondering what is the difference between

<% if current_user.present? %>

      

and

<% if user_signed_in? %>

      

+3


source to share


1 answer


No, there really is no difference.

Have a look at the metaprogrammed implementation user_signed_in?

:

def #{mapping}_signed_in?
  !!current_#{mapping}
end

      



When authenticated with a model, User

this allows:

def user_signed_in?
  !!current_user
end

      

Note: !!current_user

Returns true

if current_user

- nil

or false

. And this is exactly the same as present?

.

+3


source







All Articles