Struggling a little with getting the syntax right for a STI model. Prob
just being a bit dense.
Couple of questions I’m hoping you guys can answer:
Assume here I’ve got:
class Manager < Person
class Slave < Person
How does person[:type] differ from person.type when type is the
column used to specify the subclass. They seem to output the same
(“Manager”) but the first works with an if statement (if person[:type] =
“Manager”), the second doesn’t.
How do I force the creation method that follows a form submission to
put something into a particular subclass. At the moment I have one form
that can handle all the subtypes and there’s a hidden field <%=
hidden_field(‘person’, ‘type’, “value” => @person[:type]) %> that varies
depending on how it’s called, e.g. @person = Manager.new or @person =
Slave.new. However, although that seems to pass the correct variables
along, the type is left as null.
There’s not much on the wiki (or anywhere else) on STI, so any help
would be greatly appreciated, and I’ll update the wiki.