Rails Active Record accessing the data problems

I’ve got a users table and a usergroups table and the user_groups_users for the many to many relation.

Now I want to get all user groups in which a user is signed in …

I tried this:

@usergroups = UserGroup.users.where('client_id = ?', @current_client.id).order('name')

But then I got this error:

undefined method `users' for #<Class:0x0000000fc027b8>


class User < ActiveRecord::Base
   has_and_belongs_to_many :user_groups

class UserGroup < ActiveRecord::Base
   has_and_belongs_to_many :users

Source: ruby

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.