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 Williams 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 --

Max Williams 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.

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

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.

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.

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.

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