Single-table inheritance and select

I’m getting some weirdness trying to use a select widget to choose
the type from a collection of three objects sharing a database table
via single-table inheritance (STI). I’d be grateful for any advice on
whether it’s a bug or a feature, if a feature why and how I can more
easily do what I’m trying to do.

So I have the usual STI setup, with a ‘type’ field in the table to
distinguish three objects, all subclasses of the same thing. It would
seem logical to be able to create new objects by creating the
superclass and setting the type along with all of the other fields –
that way I can use one form to create all three. Unfortunately

<%= select ‘’, ‘type’, %w{a b c} %> (where
just stands for the name of my superclass)

blows up with an error: wrong argument type String (expected Module).

The obvious symbol-using variant does the same thing. So do the
variants with ‘class’. But

<%= text_field ‘’, ‘type’ %> and
<%= select ‘’, ‘<any_other_field_name>’, %w{a b c} %>

both work fine.

Any clues as to what’s going on, why and how to fix / sidestep? (I’ve
tried 1.1.6 as well as 1.1.4)

And, as we’re on the subject, should it be ‘type’ or ‘class’? Both
editions of the pragmatic book use ‘type’ but there is the occasional
message saying that this is deprecated. Or do we care?

thanks in advance



John B.

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