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