Need some hints on architecture

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

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

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)?

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.
[email protected]