I found the problem, ".where" returns an array and that was my mistake.
user = User.where(:user_id => user_id)
So instead of ".where", I used ".find_by_userid".
user = User.find_by_user_id(user_id)
This is Dynamic Querying, and it returns one entity which made it possible to do the following:
user_group = user.user_group