When a user does something like create a blog post or upload a photo, a user_id gets set.
When should that be set? I’ve typically done it in the controller…
def create
@blog = Blog.new(params[:blog])
@blog.user_id = current_user.id
end
But is there a more appropriate place/way to do that?
I think the controller is a great place to do this. You’re tying together application states (the currently logged in user and a newly created blog) which is what controllers are for. I would clean up that code a little bit though:
No reason to have two lines when one will do!