Hi i'm freshman to Ruby on Rails. I'm trying to make current_user method and i have a question. Many Rails courses make current_user method like this.
helper_method current_user
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
This method stores current user in instance variable. But in view file, most of course use method in view like this.
<% if current_user %>
...
<% end %>
I'm wondering why "store current user in instance variable" good right practice, even we will not use instance variable in view file. I'm still lacking in skills, so I have this question, so please take good care of me. Thanks.