Select list error - following Agile guide

I would swear that I am tracking exactly the method used in Agile
book…

TypeError in Placements#edit
Showing app/views/placements/_form.rhtml where line #33 raised:

wrong argument type String (expected Module)

Extracted source (around line #33):

30:


31: <label for “type”>Type<%=
32: options = [[“Select Program Type”, “”]] +
Placement::PROGRAM_TYPES
33: select(“placement”, “type”, options) %>
34:
35:
36:

inside of placement.rb (model)

PROGRAM_TYPES = [
[ “PAH”, “PAH” ],
[ “16 Hour”, “16 Hour” ],
[ “24 Hour”, “24 Hour” ],
[ “24 Hour DD”, “24 Hour DD” ]
].freeze

Why isn’t this working?

Craig

‘type’ attribute is reserved for STI (single table inheritance). Try
to change the name of this attribute from ‘type’ to something else and
check whether it helps.

Kent.

duh - gasp! always overlook the obvious is my motto.

At least I typed it right.

thanks

Craig

Yes, “type” is meant for use with STI, but, right now I’m having
similar trouble.

My table, advertisers, uses the special “type” field. I want users to
be able to select the type of advertiser during creation via a select
box. Is this possible? (I assume it would be possible using
select_tag(), but I’d rather use select().)

The types of advertisers are stored as string in an array in
environment.rb. The code I’m using works fine - I’ve tested it in
console.rb. But here it is anyway…

<%= select ‘advertiser’, ‘type’, ADVERTISERS.map { |at| [ at, at ] } %>

Has anyone else run into this problem? Is it possible to use the
“type” field like this?

  • Rabbit

Actually, you can change the default name of this column from ‘type’
to something else by overriding the inheritance_column method of the
ActiveRecord::Base class.

Kent.

Since it’s a reserved name, you are always gonna struggle with using a
table with a column named ‘type’ - that was what I gathered and so I
simply renamed the column and moved on.

as for a selection list of values…this has worked for me…

<%= options = [[ ‘Select Type’, ‘’]] + model::METHOD, select
‘controller’, ‘field’, options %>

ie…my model and controller being ‘placement’ and my METHOD being a
list of values in the placement model called “PROGRAM_TYPES”…

<%= options = [[ ‘Select Type’, ‘’]] + placement::PROGRAM_TYPES select
‘placement’, ‘pltype’, options %>

Craig

I want to use the type column’s special attributes. Maybe I can’t.

Oh well.

  • Rabbit

yeah but it was a part of a bunch of new tables tossed together without
any meaningful data or significant amount of coding (since the amount of
coding I have gotten done is directly proportionate to my lack of
knowledge which inch by inch grows and in another 5 years…I think I
will understand things). If it were an existing table with data, I might
have opted for that but it did seem to me when that was first brought up
that I needed to bail on the column name ‘type’ since seemed to be the
type of thing that would aggravate me forever in a million different
ways…including outside of the ruby/rails environment.

:wink:

Thanks

Craig