Robert
Robert

Reputation: 311

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

Working on devise and was wondering what the difference are between

<% if current_user.present? %>

and

<% if user_signed_in? %>

Upvotes: 3

Views: 450

Answers (1)

spickermann
spickermann

Reputation: 106982

No, there isn't really a difference.

Look at the meta-programmed implementation of user_signed_in?:

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

When authenticating against a User model this resolves to:

def user_signed_in?
  !!current_user
end

Note: !!current_user returns true if current_user is nil or false. And that is exactly the same what present? does.

Upvotes: 4

Related Questions