user984621
user984621

Reputation: 48453

Relationships between 2-3 models

I have following models:

User

has_many :roles, :through => :assignments

Role

has_many :assignments
has_many :users, :through => :assignments

Assignment

belongs_to :user belongs_to :role

Whole evening I am trying to find a way, how to print somewhere, what kind of role has currently log in user. I tried already stuffs like

@log_in_user.roles.type_of_role

or

@log_in_user.assignments.type_of_role

but unfortunately nothing succes... Could anyone give me any idea how get this information?

Thanks a lot!

Upvotes: 0

Views: 37

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107728

Use this:

@log_in_user.roles.map(&:type_of_role)

That will return an array of the type_of_role attribute for each role the user has.

Upvotes: 1

Related Questions