Controller and model strategies

Hi,

I’m very new to ROR and have aquestion about which stregy to use for
using controllers.
Lets say i have 3 classes:

order
order_lines
customer

I would like to build an application where i can create customer.
create orders (which has belongs to an customer) and add orderlines
(which belongs to an order)

Should i create one controller for each model (eg. order_controller,
customer_controller…) or should I just crceate one
ordermanagement controller that handles them all.

Please provide me with some pros and cons between the two options and
which one you prefer, and way.

//John

I would do an AJAX based cart for this. In this case, since you’re not
sending complete new page refreshes, but just updating parts of an
existing page, you’d probably have a controller for orders, where you
can expand / hide / delete / whatever for each order_line. So, you
would have a single controller for both order and order_line (not
order_line_s_ class).

If, however, you don’t use any AJAX, and each click causes a different
page to appear, and you want each order_line to appear in its own
page, you’d probably like to use REST for keeping your calls standard.
Then, you’ll have an orders_controller and under it (in the REST path
hierarchy) you’d have an order_lines controller.

Customers, being quite independent of the orders would probably get
their own controller.

Amir

John Gunnarsson wrote:

Hi,

I’m very new to ROR and have aquestion about which stregy to use for
using controllers.
Lets say i have 3 classes:

order
order_lines
customer

I would like to build an application where i can create customer.
create orders (which has belongs to an customer) and add orderlines
(which belongs to an order)

Should i create one controller for each model (eg. order_controller,
customer_controller…) or should I just crceate one
ordermanagement controller that handles them all.

Please provide me with some pros and cons between the two options and
which one you prefer, and way.

Hi John,

I’m new to Rails too. I curious what replies you will get back.

From what I’ve seen, the general approach would be to have three models,
three controllers, and probably three sets of views.

For example, with customer. You need to create, update, and manage a
customer as its own entity.

There are concepts to an order that need to be managed without customers
or order lines coming into play like marking it shipped or marking it
over due, etc.

The book “Ruby by Rails” that you can by from the Pragmatic Programmer
people goes through a shopping cart example that is exactly what you are
doing (and that is just the front 1/3 or the book). By the time you are
done, you have AJAX and all sorta of nifty things added It is a very
good book and example.

Then the later part of the book are somewhat a reference (but not to
replaced with rdoc).

And, the new toy in town is “REST”. It very much says that you would
have three controllers. The book describes it a bit. There is a web
cast that describe it too. It is a little controversial I suppose in
that we have been doing “REST” all along. But the Rails “REST” implies
some things and it turns out to help rethink your applications.

hth
Perry