Model/controller pair with different names?

I want to use a controller that has a different name to the model it
uses. Can i do this in rails? Something like

class FooController < ApplicationController
model => “AModelWithALongClunkyName”

?? Ie, to override rails configuration in this instance?

Max W. wrote:

I want to use a controller that has a different name to the model it
uses. Can i do this in rails? Something like

class FooController < ApplicationController
model => “AModelWithALongClunkyName”

?? Ie, to override rails configuration in this instance?

Never mind, i managed to figure it out: my problem was actually with
resource_this, which was generating my controller methods. I just
needed to pass a :class_name option to resource_this.

Hi –

On Thu, 13 Mar 2008, Max W. wrote:

?? Ie, to override rails configuration in this instance?

Never mind, i managed to figure it out: my problem was actually with
resource_this, which was generating my controller methods. I just
needed to pass a :class_name option to resource_this.

In general it’s worth knowing that the controller-model linkage is
essentially arbitrary. Controllers are just objects, and models are
classes. All model classes are visible to all controllers. You have to
decide how you want your domain controlled – that is, how the gears
work between your controller layer and your model layer. There are
some high-level conventions and bundled behaviors, like resource
routing, that save you from having to think it through completely from
scratch every time, but it’s still always under your control.

David


Upcoming Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS, April 14-17 2008, New York City
CORE RAILS, June 24-27 2008, London (Skills Matter)
See http://www.rubypal.com for details. Berlin dates coming soon!

I think one of the weaknesses in the RoR community right now is that
everyone has just assumed that the default scaffolding for RESTful
resources is THE way that resources are supposed to be viewed. There
has not been a very good explanation (at least not one that anyone has
listened to) that resources are addressable objects of any type. As
such they do not necessarily map 1-1 with domain models. As I have
pointed out previously, the restful_authentication plugin makes the
point by manipulating a ‘session’ object that has no domain model –
it’s purely a notional resource that relates to the user logged into
the site.

The scaffolding is a simplifying step, but it’s not the only way. As
David says, the choice is yours.

On 3/13/08, AndyV [email protected] wrote:

the site.
Yep. Many people seem to have a mindset that resources ARE models,
but to my mind resources are really aspects of controllers.

I’d say that resources are controllers, except that in general a
controller (can) represent(s) both a collection of resources and the
individual elements in that collection.

While it’s natural to use a(n) (ActiveRecord) model to implement
persistent resources, it’s by no means the sole implementation.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

AndyV wrote:

I think one of the weaknesses in the RoR community right now is that
everyone has just assumed that the default scaffolding for RESTful
resources is THE way that resources are supposed to be viewed. There
has not been a very good explanation (at least not one that anyone has
listened to) that resources are addressable objects of any type. As
such they do not necessarily map 1-1 with domain models. As I have
pointed out previously, the restful_authentication plugin makes the
point by manipulating a ‘session’ object that has no domain model –
it’s purely a notional resource that relates to the user logged into
the site.

The scaffolding is a simplifying step, but it’s not the only way. As
David says, the choice is yours.

That’s all too true. My problem (and maybe others) is that i dove into
the REStful stuff without fully understanding it (like they did with
Rails) and so tended to slavishly copy the examples in every situation,
which of course isn’t advisable.

Thanks a lot guys.

Maybe we should have pitched a “What the heck is a resource” talk for
RC08!