# Using vs. administer a rails application

**URL:** <https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979>\
**Category:** Rails\
**Created:** [January 29, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979 "2009-01-29T23:19:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [January 29, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979/1 "2009-01-29T23:19:57Z")

</div>

Good evening,

there’s a question, I can’t really answer for myself. Let’s assume,  
I’ve got a rails application for selling cars. A user can create an  
advertisement by choosing the corresponding model from a table  
“car\_models” and then add additional information. The user should  
always be able just to _read_ the “car\_models” table, not to change  
it. On the other hand, there’s an assistant who administers the  
“car\_models” table, adding, changing and removing entries.

So, where we are? We have our “CarModel” controller with its CRUD  
methods. And, let’s assume, we have a roled based access control  
implemented. A normal user is a group member of “STD\_USER”, for  
example. So he may only access the “get” oder “read” methods,  
whatever. The assistant however is member of the group “STD\_ADMIN”,  
for example, and has access to all methods of our “CarModel”  
controller.

Although this looks secure, I must confess, that I am concerned. What  
if the RBAC fails for some reasen? What if a normal user gets  
accidentally in the admin group?

Wouldn’t it be better to separate those functionalities? Let’s say:  
one administration application and one great wide world application.  
I’m not convinced myself. How do you handle this?

I would be very happy about suggestions.

Thank you very much!  
ms

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [January 30, 2009, 6:49am UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979/2 "2009-01-30T06:49:30Z")

</div>

Yeah, it’s better to separate them, but you’re still going to be in  
the same boat as before, really: it’s going to be down to whatever  
qualifier you decide to split the access levels on.

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [January 30, 2009, 10:04am UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979/3 "2009-01-30T10:04:30Z")

</div>

Well it all in relations.  
CarModel controller - has in info.  
has\_many :advertisments

All controller actions regarding this model, is garded by if the user  
is adminnistrator.  
hence in your user model, you put an bool called “admin”.  
So all actions in the controller if garded with if @user.admin

For the advertisment you have:  
And a belongs\_to :carmodel

id  
Carmodel\_id  
-----lots of extra info.

Regards  
svend

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [January 30, 2009, 11:13am UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979/4 "2009-01-30T11:13:15Z")

</div>

I use Goldberg ([http://wiki.github.com/urbanus/goldberg](http://wiki.github.com/urbanus/goldberg)) to manage  
this situation. It’s possible to restrict access to controllers/  
actions by roles. So you can forbid edit/update to normal users (or on  
the other hand, forbid everything then allow only view for normal  
users).

But anyway, you are not protected against a configuration mistake or  
any security bug…

Jej

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [January 30, 2009, 11:35am UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979/5 "2009-01-30T11:35:34Z")

</div>

I use this approach, too. Moreover I like to separate all admin  
controllers in their own namespace. Unfortunately in version 2.2  
creating scaffold in namespace creates tables with admin\_ (if  
namespace is admin) prefix which is annoying and looks to me as a  
bug.

Also in your controller you can put:

before\_filter :require\_admin

where require\_admin is a method defined in your application.rb and  
returns true if current user has admin flag set.

You can use before\_filter in another way to require admin just for  
some actions:

before\_filter :require\_admin, :except =\> [‘index’]

of

before\_filter :require\_admin, :only =\> ‘destroy’

Regards,  
Bosko

On Jan 30, 10:03 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [January 30, 2009, 1:13pm UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979/6 "2009-01-30T13:13:06Z")

</div>

> not the one with  
> Goldberg.

You should 😉

I think it’s better to group the security concerns in the same place  
(ie. in golberg) rather than spread them amongs different  
before\_filters.

But whatever, the both rely on the skills of the coder!

Jej

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [January 30, 2009, 11:39am UTC](https://www.ruby-forum.com/t/using-vs-administer-a-rails-application/158979/7 "2009-01-30T11:39:41Z")

</div>

By “this approach” I meant the one Svend gave :-), not the one with  
Goldberg.

Regards,  
Bosko

On Jan 30, 11:34 am, Bosko I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
