Hey all --
This is a problem I've been banging my head against for a week or so,
because Rails doesn't provide a decent way to use inheritance in one's
model very well.
Let's suppose I have the following class definitions:
class Person < ActiveRecord::Base
class Employee < Person
class Manager < Employee
I'd like for a view to display all the people in the system, but only
display, for example, group_names for those people who are also
managers. This would come in handy if I wanted to show a table of all
employees, for example.
The only decent way I can come up with is to use helper modules to do
the dirty work of rendering. (Not too disgusting, but I wish the helper
modules could just be classes, so I could use inheritance here too. I'd
rather not have helper modules replicate the inheritance tree, e.g.
forcing the ManagerHelper module to know that it must call the
EmployeeHelper module's methods. I'd rather just use 'super'.)
The problem is that I'm now stuck either 1) adding information and the
appropriate reader method to my model classes about which columns to
display (e.g. let's show 'serial_number', but not 'hashed_password'),
and in what order (e.g name first, then serial_number), or 2)
delegating this to other classses, which will be by their very
definition coupled to the model classes -- almost as ugly IMO.
I've looked at the Streamlined framework, but it doesn't quite
accomplish what I want.
Has anyone tried to do something like this? What's the best way to
approach this issue?