ruby - Rails - how to find out user's role in the system? -
i have following models:
class role < activerecord::base has_many :assignments has_many :users, :through => :assignments end class assignment < activerecord::base belongs_to :user belongs_to :role end class user < activerecord::base has_many :assignments has_many :roles, :through => :assignments ... end i trying find out user's role, when try
user.assignments.name it doesn't print out user's role table roles (column name).
how print out that?
you need map on association in order specific field:
user.roles.map(&:name)
Comments
Post a Comment