user.roles -- How do you list the role names of the user?

B

Bob Sanders

Hello,

I want to list out the role names that belong to a user. I have
user.roles as the table, so I'm interested in the "name" column on that
roles table. If I want to separate the names using a comma [ e.g. using
join(", ") ], how would I do it?

For instance:

<% for role in user.roles %><% role.name %><% end %>

displays all of the roles of the user, but without the comma. There must
be a better way to do it (a less tedious way), and also separate them
with commas?

Any idea?
 
J

James Britt

Bob said:
Hello,

I want to list out the role names that belong to a user. I have
user.roles as the table, so I'm interested in the "name" column on that
roles table. If I want to separate the names using a comma [ e.g. using
.join(", ") ], how would I do it?

For instance:

<% for role in user.roles %><% role.name %><% end %>

displays all of the roles of the user, but without the comma. There must
be a better way to do it (a less tedious way), and also separate them
with commas?
Any idea?

What happens when you do user.roles.join( ',' ) ?

You may need to explain more about the object model. Is this part of an
ORM library? Og? Sequel? ActiveRecord?
 
C

Clifford Heath

James said:
What happens when you do user.roles.join( ',' ) ?
You may need to explain more about the object model. Is this part of an
ORM library? Og? Sequel? ActiveRecord?

It'll be a Rails question. Please take Rails questions to the Rails list.

The OP wants <%= user.roles.map(&:name)*',' %>

Clifford Heath.
 
B

Bob Sanders

Clifford said:
It'll be a Rails question. Please take Rails questions to the Rails
list.

The OP wants <%= user.roles.map(&:name)*',' %>

Clifford Heath.

Clifford! Thank you, man!

I didn't see your solution before. You got it. Thank you, thank you,
Clifford :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top