Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > user.roles -- How do you list the role names of the user?

Reply
Thread Tools

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

 
 
Bob Sanders
Guest
Posts: n/a
 
      11-09-2007
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?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
James Britt
Guest
Posts: n/a
 
      11-09-2007
Bob Sanders wrote:
> 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?





--
James Britt

"Tear it up and start again."
- Anonymous

 
Reply With Quote
 
 
 
 
Clifford Heath
Guest
Posts: n/a
 
      11-09-2007
James Britt wrote:
> Bob Sanders wrote:
>> I want to list out the role names that belong to a user.
>> <% for role in user.roles %><% role.name %><% end %>

> 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.
 
Reply With Quote
 
Jacob Basham
Guest
Posts: n/a
 
      11-09-2007
Voila

<%= user.roles.join(",&nbsp;") %>

http://www.ruby-doc.org/core/classes/Array.html#M002205

Jake

On Nov 8, 2007, at 11:58 PM, Bob Sanders wrote:

> 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?
> --
> Posted via http://www.ruby-forum.com/.
>



 
Reply With Quote
 
Bob Sanders
Guest
Posts: n/a
 
      11-09-2007
Jacob Basham wrote:
> Voila
>
> <%= user.roles.join(",&nbsp;") %>
>
> http://www.ruby-doc.org/core/classes/Array.html#M002205
>
> Jake


Hi Jake, I tried that -- and ended up with a pound sign (#)

I'm guessing that brings up an array, and I'll have to incorporate the
"name" in there somehow

e.g. user.roles[name].join(",&nbsp;")

(which is probably totally wrong)

any ideas guys?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Bob Sanders
Guest
Posts: n/a
 
      11-09-2007
Clifford Heath wrote:
> James Britt wrote:
>> Bob Sanders wrote:
>>> I want to list out the role names that belong to a user.
>>> <% for role in user.roles %><% role.name %><% end %>

>> 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.


Clifford! Thank you, man!

I didn't see your solution before. You got it. Thank you, thank you,
Clifford
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Jacob Basham
Guest
Posts: n/a
 
      11-10-2007
Ahh yes, I missed that part!

On Nov 9, 2007, at 12:23 AM, Bob Sanders wrote:

> Jacob Basham wrote:
>> Voila
>>
>> <%= user.roles.join(",&nbsp;") %>
>>
>> http://www.ruby-doc.org/core/classes/Array.html#M002205
>>
>> Jake

>
> Hi Jake, I tried that -- and ended up with a pound sign (#)
>
> I'm guessing that brings up an array, and I'll have to incorporate the
> "name" in there somehow
>
> e.g. user.roles[name].join(",&nbsp;")
>
> (which is probably totally wrong)
>
> any ideas guys?
> --
> Posted via http://www.ruby-forum.com/.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Removing file names with '.' in their names from list? Sfdesigner Sfdesigner Ruby 5 08-13-2007 02:38 AM
AzMan Role Based Security vs. ASP.NET Role Based Security Kursat ASP .Net Security 1 05-07-2007 01:33 PM
Role-Based Security: ACLs and Role Hierarchies Liet Kynes ASP .Net 0 11-26-2003 08:08 AM
Role-based security: Access the role of current user Jesper Stocholm ASP .Net 2 08-23-2003 06:59 PM



Advertisments