# LoginGeneratorACLSystem Issue

**URL:** <https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849>\
**Category:** Rails\
**Created:** [April 14, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849 "2006-04-14T22:29:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 14, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849/1 "2006-04-14T22:29:06Z")

</div>

Hello all,

Again, thank you all in advance for any help here. I am trying to figure  
out how to show the role associated with a user, in a template. I am  
using the LoginGeneratorACLSystem along with the LoginGenerator. I can  
show the first name of the user by writing “\<%=  
session[:user].first\_name %\>” but when I write “\<%=  
session[:user].roles.name %\>” it spits out “Role”. I am not sure what I  
am doing wrong.

Essentially what I am trying to do is lock down user actions based on  
what role they have. If anyone know of a “better” way of doing it than  
using LoginGenerator along with the LoginGeneratorACLSystem I appreciate  
the input.

Sincerely,

Robert D.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 15, 2006, 3:49am UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849/2 "2006-04-15T03:49:32Z")

</div>

Hey Robert, could you post the exact error message that you getting so  
that  
we can better assist you?

Thanks in advance,

-Conrad

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 15, 2006, 5:09am UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849/3 "2006-04-15T05:09:26Z")

</div>

Conrad T. wrote:

> Hey Robert, could you post the exact error message that you getting so  
> that  
> we can better assist you?
> 
> Thanks in advance,
> 
> -Conrad

Conrad,

There is not an error produced, per se, but rather a lack of correct  
information showing. Here is the model code:

User Model:  
has\_and\_belongs\_to\_many :roles

Role Model:  
has\_and\_belongs\_to\_many :permissions  
has\_and\_belongs\_to\_many :users

Permissions Model:  
has\_and\_belongs\_to\_many :roles

Now, the permissions and roles definately work correctly, however, when  
I insert this code, “\<%= session[:user].roles.name %\>” into the  
“welcome.rhtml” page that is the default after a user logs in, this is  
what show in the browser: “You are logged in as an Role”. I would like  
to show the actual role of the user, such as “Admin”, etc.

Thank you for your help.

Sincerely,

Robert D.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 15, 2006, 1:56pm UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849/4 "2006-04-15T13:56:46Z")

</div>

Chris,

I will try this first thing today. Thank you for your help. I have been  
using the console (to a limited extent) and have found it extremely  
useful. I am also studying Ruby more so that I will stop asking so many  
noob-like questions and will hopefully be able to help out more. Thanks  
again.

- Rob D.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 15, 2006, 9:48am UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849/5 "2006-04-15T09:48:46Z")

</div>

I’m not familiar with LoginGenerator, but I think the problem is that  
session[:user].roles will produce many answers (a user can have many  
roles, right?)-- I think you should probably get an array of Role  
objects returned. You’ll need to iterate through that array to get the  
roles the user has (which may only be one) – something like:

```
You are in the following group(s):
<% for role in session[:user].roles %>
   <%= role.name %>
<% end %>

```

It’s always worth turning to the console when you have a strange error  
like this (ruby script/console). Takes about 30 secs and gives you an  
instant feedback on what sort of object is being returned. Hope this  
helps.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849/6 "2006-04-15T14:18:29Z")

</div>

Chris,

Worked like a charm! Thank you again for your help.

- Rob D.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 15, 2006, 2:39pm UTC](https://www.ruby-forum.com/t/logingeneratoraclsystem-issue/57849/7 "2006-04-15T14:39:41Z")

</div>

Glad to have been able to help
