Abstract Class/Model

Hi all -

I’d like to create an abstract model that other certain models can
inherit from. I know that I’ll need to use the abstract_model? to
return true to set that up.

The reason I’d like to use an abstract model is I’d like to be able to
force a sub-class to include a certain attribute if it doesn’t already
include it (in the database). Such as ‘Title’.

The reason for needing this is that different models I have will be
used as news categories, so I need a common attribute that all have the
same name so that in my views I can just call the one accessor with the
same name.

I hope that makes sense.

Is there anyway I can do this?

Regards

David W.

On 1/15/07, David [email protected] wrote:

The reason for needing this is that different models I have will be
used as news categories, so I need a common attribute that all have the
same name so that in my views I can just call the one accessor with the
same name.

I hope that makes sense.

Is there anyway I can do this?

The best option is to just add a title column to every table. But if
you really want to use a common base class…

class Foo < ActiveRecord::Base
self.abstract_class = true
end


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs