Does the model and the controller share a 1to1 relatioship?

Hi all
I am a very experienced programmer (and therefor can appriciate the
rails framework as the right thing) But a totally new to Rails.
I am trying to build a website that includes a front-end for users and
an admin system(CMS) for the web administrator.

I have around 12 different tables that supposed to be managed by the web
administrator. For each one of them, I created a model.

Now, I am looking to create the CMS and I would have been more then
happy to do the following:

1)Create an “admin” controller
2)“Scaffold” all the models under that controller

e.g.

AdminController < ApplicationController
Scaffold table1
Scaffold table2
Scaffold table3
etc.

Well… I can’t

This lead brought me to the big question:
Does the model and the controller share a one to one relationship?
Thanks a lot
Danny

Hi Danny,

As far as I know if you’re using scaffolding then yes, its 1
controller per model.

However if you are writing the controller code yourself there is no
such limit, you can ‘access’ as many models as you want from as many
(or as few) controllers as you want.

Generally speaking I try to keep related stuff in the same controller,
rather than sticking to 1:1

HTH

Peter

On Oct 17, 9:34 am, Danny Y. [email protected]

The controller and model do not share a 1 to 1 relationship although
in many apps that is what you end up with. It keeps the app simple
and easy to understand when you go back to it later.

The think I love about rails is that most of the time when I’m
debugging, I read the error and immediately know what the problem is.
Recently, I took a look at a rails CMS/Shopping cart called
Substruct. It works well but when I tried to customize it, I found I
spent most of my time digging through controllers and models trying to
figure out how it worked so I could change it for my needs. I could
not find a pattern of mapping models to controllers at all and after a
while, it reminded me of debugging php apps.

Some apps I’ve written contain controllers that are not mapped 1 to 1
with models and that is fine because in that instance there was a good
reason for it but even in those apps, most of the models/controllers
are 1 to 1.

For me, the organization of controllers and models is about keeping
the code clean and easy to understand and come back to later.

On Oct 17, 4:34 am, Danny Y. [email protected]

On 10/17/07, Danny Y. [email protected] wrote:

Scaffold table1
Scaffold table2
Scaffold table3
etc.

Well… I can’t

This lead brought me to the big question:
Does the model and the controller share a one to one relationship?

No, there is no forced relationship between controllers and models.

The issue with multiple scaffolds in the controller is that you get
duplicate action names generated. But you can do it with a :suffix
option.

From the API docs for the scaffold method:

“It’s possible to use more than one scaffold in a single controller by
specifying options[:suffix] = true. This will make scaffold :post,
:suffix => true use method names like list_post, show_post, and
create_post instead of just list, show, and post. If suffix is used,
then no index method is added.”