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 trial
Mickey Asavanant
8,237 PointsWhy are we assigning current_user to g.user? Given that we can access current_user at any time.
At 2.58, Kenneth created the model by using the g.user as the parameter to the method call (line 87). Later at 4.19, he assigned g.user = current_user (line 33) and import relevant module associating with the current_user.
My question is that why are taking two steps to do thing at line 87. Specifically, what is the downside of doing something like this:
models.Post.create(user = current_user. get_current_object(), ...)
rather than doing the Kenneth's way of :
models.Post.create(user=g.user. _get_current_object(), ...)
Or this is just for the sake of showing how to use g object?