Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Sanchez
3,325 Pointsg.user vs. current_user
What is the difference between the two and when should each be used? Thanks!
John
2 Answers
Hunny None
Courses Plus Student 198 Pointsg.user is used to make the a variable global so it can be accessed in any scope where current_user is a object which tells us current active user, we use g.user to make the current_user object global so it can be used anywhere ...
Hope that helps
Binyamin Friedman
14,615 PointsBut isn't current_user also global?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherGreat answer with one minor nitpick.
g
can be accessed in any view, not any scope. You can't, for instance, useg
in your models without some juggling.nuri jeon
14,376 Pointsnuri jeon
14,376 PointsI still am not quite sure about this part. So when we use the post view, we need global object but when we use stream view, we don't need it to be global? Please somebody help @@ I don't understand when to use g.user and when to use current_user stilllll Thank you X(