I would code 3 controllers: contacts, transactions and clients. I don't know how similar the admin functionality of these controllers will be. If the difference isn't very big you could write a macro/procedure that defines the basic crud for you. This is like scaffold() but it could do things that scaffold doesn't do. It could for example add filters to protect the new/edit/update/create/destroy actions.
Now your controllers look like this:
Code:
class ClientsController
admin :clients # this is the macro/procedure you wrote
end
admin :clients produces this:
Code:
class ClientsController
def new; ... ; end
def create; ... ; end
def edit; ... ; end
def update; ... ; end
def destroy; ... ; end
# and it protects them with before_filters:
before_filter :authorize, :only => [:new, :create, :edit, :update, :destroy]
def authorize
if the_logged_in_user.admin?
# continue
else
# display not authorized page
end
end
end
Now you have a nice controller structure and dry+easy code. (you reuse the admin() macro for the other controllers)
Bookmarks