# Need some hints on architecture

**URL:** <https://www.ruby-forum.com/t/need-some-hints-on-architecture/121611>\
**Category:** Rails\
**Created:** [November 29, 2007, 10:30am UTC](https://www.ruby-forum.com/t/need-some-hints-on-architecture/121611 "2007-11-29T10:30:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elinor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elinor](https://www.ruby-forum.com/u/elinor)\
**Post date:** [November 29, 2007, 10:30am UTC](https://www.ruby-forum.com/t/need-some-hints-on-architecture/121611/1 "2007-11-29T10:30:02Z")

</div>

Hi all,

I’ve a simple web app that concerns employee’s and their  
(work/lunch)shifts. I’ve succesfully included HABTM relations between  
the two tables and all works fine. But now I want to make a distinction  
between employee’s (who are also users of the web app) that are ‘mere’  
users or those that may administer the app.

Now I have two controllers, one for employee and one for shift. Also I  
have one controller for login. I need some hints to maintain the DRY  
principle of rails and also have pretty URL’s (as admin it needs to be  
like /admin/shifts/edit and for user like /shifts/view or something).  
For example I want the admin and normal user to share some views on  
data, but most of their views will be different.

It is recommended to put all actions for one database table in one  
controller, hence that I’ve created the employee and shifts tables, but  
now I am at a loss where to put and how to name the controllers (perhaps  
I have to divide the employee and shifts controllers into user and  
admin?) that control the user actions and admin actions.

I hope some of you have more experience with this thing and can give me  
some hints on how to set-up this architecture.

Elinor

---

<div class="post-metadata">

**Author:** ![elinor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elinor](https://www.ruby-forum.com/u/elinor)\
**Post date:** [November 29, 2007, 11:07am UTC](https://www.ruby-forum.com/t/need-some-hints-on-architecture/121611/2 "2007-11-29T11:07:52Z")

</div>

in the edge version of rails i would create my own namespaces for admin

the routes look like that then:

map.namespace :admin do |admin|  
admin.resources(:shifts)  
end  
map resources(:shifts) # \<- that one for the normal shifts controller

the path helpers wold look like that:

admin\_shifts\_path  
shifts\_path

both for the (RESTfull) index action

the namespace admin would get it’s own folder for the controllers in  
/app/controllers/admin

that’s a nice and clean way to do things and keep them RESTfull

---

<div class="post-metadata">

**Author:** ![elinor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elinor](https://www.ruby-forum.com/u/elinor)\
**Post date:** [November 29, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/need-some-hints-on-architecture/121611/3 "2007-11-29T14:49:33Z")

</div>

Thx for reply-ing!

I assume you mean this piece of code should be in the config/routes.rb  
file? It tells me that namespace is not known method, but I understand  
now (after reading the routes chapter of my book) that the URL is not  
dependent on the controller architecture, but it can be changed later.

The question that remains is whether I should put user actions and admin  
actions in seperate controllers (because they maintain different filters  
for access) or if it is best if they are combined and written in their  
corresponding table\_controller (all actions referring to one  
object/model/table in one controller)?

---

<div class="post-metadata">

**Author:** ![elinor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@elinor](https://www.ruby-forum.com/u/elinor)\
**Post date:** [November 29, 2007, 2:59pm UTC](https://www.ruby-forum.com/t/need-some-hints-on-architecture/121611/4 "2007-11-29T14:59:46Z")

</div>

I would put them in one controller and have the application logic(that  
distinguishes between normal user and admin user) wrap over the model.

On Nov 29, 2007 8:49 AM, Elinor B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
