I am getting the following error in Rails:
undefined local variable or method `current_user' for #<UserController:0x0000000458d708> Did you mean? @current_user
The code fragment corresponding to that error is:
authorize @current_user
As you can see, I clearly mean @current_user
like the error message suggests, and I also use @current_user
like the error message suggests. Why is Rails thinking I mean a local unexisting variable when I expect it to be global? The authorize
method is from Pundit.
I added a print statement to verify if the global variable exists, and the following code effectively prints out a valid User:
p @current_user
authorize @current_user