May I correct myself: Can I put all the tables of the database in one
model? Making one-on-one when you have 49 tables is a royal PITA!
Practical, but a PITA!
class Foo < ActiveRecord::Base
include SharedStuff
end
class Bar < ActiveRecord::Base
include SharedStuff
end
isn’t the same as what is mentioned in that posting… including the
SharedStuff module just makes those methods available to your model,
each model should still spec its own table_name. As you are set,
everything reads from ‘bartable’ if I understand the internals
correctly.
I prefer the abstract class method, and have a class GenericModel, which
defines all the default behaviors for all the other models. Centralized
cache management, polymorphic join management, all that ugly stuff you
don’t want to type more than once.
Every other model inherits from GenericModel, overriding default
behaviors if necessary. But GenericModel has no data fields, no table
names, just methods.
I also use a GenericController, and for almost all of my other
controllers, they contain nothing more than a before_filter, sometimes a
different layout, and any actions unique to their model. index, new,
edit, save, update… they all reside in GenericController. Actions not
done by all controllers, like deep copy, or PDF generation are in each
controller that supports it.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.