You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As someone new to rails and ruby, I found the use of the current_user instance variable confusing. On a single settings page hit, I found the current_user method getting invoked 6 times, and 6 hits to the user table to get the current_user. I think the instance variable helped alleviate this in section 8.2.2 of the book where the code looked like this:
With the code above, I can understand the value of the instance variable. However further along in the book, this code is refactored to the below and I can no longer see the value of the instance variable.
Would it make sense to change the current_user method to make use of the instance variable again. I've tried thinking of any security vulnerabilities this would introduce but all tests are still passing. Also db calls to user went from 6 down to 2.
def current_user
if (!@current_user.nil?)
return @current_user
end
.
.
.
The text was updated successfully, but these errors were encountered:
As someone new to rails and ruby, I found the use of the current_user instance variable confusing. On a single settings page hit, I found the current_user method getting invoked 6 times, and 6 hits to the user table to get the current_user. I think the instance variable helped alleviate this in section 8.2.2 of the book where the code looked like this:
With the code above, I can understand the value of the instance variable. However further along in the book, this code is refactored to the below and I can no longer see the value of the instance variable.
rails_tutorial_sample_app_7th_ed/app/helpers/sessions_helper.rb
Line 23 in 5f91577
Would it make sense to change the current_user method to make use of the instance variable again. I've tried thinking of any security vulnerabilities this would introduce but all tests are still passing. Also db calls to user went from 6 down to 2.
The text was updated successfully, but these errors were encountered: