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

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -