Hi,
What is && doing in the following code?
@_current_user ||= session[:current_user_id] && User.find_by(id:
session[:current_user_id])
Hi,
What is && doing in the following code?
@_current_user ||= session[:current_user_id] && User.find_by(id:
session[:current_user_id])
It’s “and”, you can see better this way:
@_current_user ||= (session[:current_user_id]) && (User.find_by(id:
session[:current_user_id]))
There are two conditions, if both return true then the assignation
happens only if @_current_user is nil.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs