# A single Administrator without boolean column in User's table?

**URL:** <https://www.ruby-forum.com/t/a-single-administrator-without-boolean-column-in-users-table/183721>\
**Category:** Rails\
**Created:** [February 19, 2010, 4:05am UTC](https://www.ruby-forum.com/t/a-single-administrator-without-boolean-column-in-users-table/183721 "2010-02-19T04:05:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlwaysCharging](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@AlwaysCharging](https://www.ruby-forum.com/u/AlwaysCharging)\
**Post date:** [February 19, 2010, 4:05am UTC](https://www.ruby-forum.com/t/a-single-administrator-without-boolean-column-in-users-table/183721/1 "2010-02-19T04:05:35Z")

</div>

Hi, I’m using Ryan Bate’s CanCan gem for my authorization (coupled  
with Authlogic for my authentication). In his railscast, he uses a  
boolean column in the database to define roles. However, my app is  
super simple and only needs one Administrator, and everyone else has  
the same permissions. How would I go about doing this?

I thought of something like:  
def initialize(user)  
user ||= User.new

```
if admin?
  can :manage, :all
else
  can :read, :all
  can :create, Comment
end

```

end

and then defining admin? as True if the current\_user’s username was  
admin, but I cant figure out where to put this, much less how to  
accomplish this correctly. Any ideas?

Or, maybe there’s even a better way?

---

<div class="post-metadata">

**Author:** ![AlwaysCharging](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@AlwaysCharging](https://www.ruby-forum.com/u/AlwaysCharging)\
**Post date:** [February 19, 2010, 5:41am UTC](https://www.ruby-forum.com/t/a-single-administrator-without-boolean-column-in-users-table/183721/2 "2010-02-19T05:41:26Z")

</div>

AlwaysCharging wrote:

> Hi, I’m using Ryan Bate’s CanCan gem for my authorization (coupled  
> with Authlogic for my authentication). In his railscast, he uses a  
> boolean column in the database to define roles. However, my app is  
> super simple and only needs one Administrator, and everyone else has  
> the same permissions. How would I go about doing this?

The way Ryan did – with a boolean column.

> I thought of something like:  
> def initialize(user)  
> user ||= User.new
> 
> ```
> if admin?
> can :manage, :all
> else
> can :read, :all
> can :create, Comment
> end
> 
> ```
> 
> end
> 
> and then defining admin? as True if the current\_user’s username was  
> admin, but I cant figure out where to put this, much less how to  
> accomplish this correctly. Any ideas?

Don’t try to be clever with your usernames. There’s no reason to  
restrict the administrator name to being “admin”, and no reason to  
restrict yourself to only having one administrator.

> Or, maybe there’s even a better way?

There is. The way Ryan did it.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
