# Using Roles but donÂ´t want to show them

**URL:** <https://www.ruby-forum.com/t/using-roles-but-dona-t-want-to-show-them/190260>\
**Category:** Rails\
**Created:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/using-roles-but-dona-t-want-to-show-them/190260 "2010-06-17T16:22:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/using-roles-but-dona-t-want-to-show-them/190260/1 "2010-06-17T16:22:31Z")

</div>

Hi everyone,

i am using roles in my project for admin and author and so on…  
This is my code  
"  
ROLES = %w[admin moderator author]

def roles=(roles)  
self.roles\_mask = (roles & ROLES).map { |r|  
2\*\*ROLES.index® }.sum  
end

def roles  
ROLES.reject { |r| ((roles\_mask || 0) & 2\*\*ROLES.index®).zero? }  
end

def role?(role)  
roles.include? role.to\_s  
end  
end  
"

But if somebody wants to sign in he can choose between admin,  
moderator, author by himself. He has to be automatically author.  
Is there a way to fix that problem?

Thanks

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [June 17, 2010, 4:26pm UTC](https://www.ruby-forum.com/t/using-roles-but-dona-t-want-to-show-them/190260/2 "2010-06-17T16:26:21Z")

</div>

On Jun 14, 4:59 pm, Mark [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> But if somebody wants to sign in he can choose between admin,  
> moderator, author by himself. He has to be automatically author.  
> Is there a way to fix that problem?

Don’t put a role popup on the form ? ( & disallow mass assignment for  
the attribute)

Fred

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [June 17, 2010, 11:01pm UTC](https://www.ruby-forum.com/t/using-roles-but-dona-t-want-to-show-them/190260/3 "2010-06-17T23:01:19Z")

</div>

Thank you for your answer but i don’t understand what you mean.  
I don’t have a popup on the form.

In my view there are in the sign in form the three checkboxes

[]admin  
[]moderator  
[]author

So there you can choose what function you want to have. But no one  
else has to be admin. Everybody has to be author. So I just want du  
show one checkbox “author”. But i can not delete admin and moderator  
because my admin account hasn’t got the admin functions if i delete  
it.  
You know what i mean?

So i just want to fade out the other oppertunities.

Thanks very much

On 14 Jun., 18:07, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [June 17, 2010, 11:11pm UTC](https://www.ruby-forum.com/t/using-roles-but-dona-t-want-to-show-them/190260/4 "2010-06-17T23:11:16Z")

</div>

On 17 June 2010 21:51, Mark [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> else has to be admin. Everybody has to be author. So I just want du  
> show one checkbox “author”. But i can not delete admin and moderator  
> because my admin account hasn’t got the admin functions if i delete  
> it.  
> You know what i mean?
> 
> So i just want to fade out the other oppertunities.

Could you not top post please, it is easier to follow the thread if  
comments are inserted into the previous email. Thanks

Why not just do not put the options on the sign in form? If it always  
has to be author there is no need to put it on the form at all. This  
does not mean that you have to do away with the roles, just do not  
give the option to set it on the signup form. Presumably you have an  
alternative method of setting up admin and moderator roles.

Colin
