MVC question

Should I create a separate controller for each model or should I use 1
controller for all models?
Having 1 “admin” controller for all backend stuff seems logic to me, but
when I scaffold it rather makes 1 controller per model.

I’m fairly new to the MVC pattern, so what’s the prefered way of doing
it?

I’m also wondering if the API is up to date? When scaffolding, the
rhtml’s make use of “mymodel.send(column.name)”. I tried to lookup the
send() function in the API(ActiveRecord::Base) but it was nowhere to be
found.

thx in advance.

btw, atm I’m sticking everything in 1 controller cuz I have no idea how
to assign 1 layout to different controllers/views.

Bart E. wrote:

btw, atm I’m sticking everything in 1 controller cuz I have no idea how
to assign 1 layout to different controllers/views.

I’m pretty new too, but to use a layout for multiple controllers, just
put the line:

layout “name_of_layout”

at the top of your controller class definition and obviously make sure a
file with this name exists in the layouts folder.

On Aug 1, 2006, at 8:28 AM, Bart E. wrote:

rhtml’s make use of “mymodel.send(column.name)”. I tried to lookup the
send() function in the API(ActiveRecord::Base) but it was nowhere
to be
found.

thx in advance.

I think organization of controllers is partly up to you. I tend to
use one controller per “area” of my app (usually one model, sometimes
not) and just use before_filter to lock out administrative
functions. If you’re running into path problems with the layouts
(like I did when I was first starting) you can just use the path to
the layout file starting just after ‘app/views/’ so if a layout was
somewhere other than app/views/layouts you can still get at it.

The reason you can’t find send() in rails api is that it’s a ruby
function. If you’re curious, type “ri send” on the command line.
-Mat

On 8/1/06, Bart E. [email protected] wrote:

rhtml’s make use of “mymodel.send(column.name)”. I tried to lookup the
send() function in the API(ActiveRecord::Base) but it was nowhere to be
found.

thx in advance.

The controller should encapsulate a logical group of actions. Your
example
of an admin controller to handle backend stuff is correct. The
scoffolding
is very rudimentary, even in the way it creates controllers. The job of
the
scaffolding is to create CRUD functionality on a single model (Create
Read
Update Delete). Sometimes this is what you need to do in production,
often
it is not. Your instinct to make the controllers more logically
organize
like actions - even though they go across multiple models - is correct.

The send() function does not show up in the rails api because it is a
built
in part of the Ruby language. Check out www.rubycentral.com

-Derrick

thx for the replies.
It’s probably gonna take a while before I’ll be productive with rails
but I’m liking it so far. :slight_smile: