I have a C programming background and I am learning Ruby/Rails for a side project. Currently I am struggling to understand how the scoping of variables works. Here is an example
You have to initialize @current_user
on each request, not only after the user logs in. Controller instance variables do not persist across requests.
Here's a common way to do this:
ApplicationController
that retrieves the user ID from the session and initializes the instance variable.