(please note that what follows are the actual names of my objects and
db tables, compared to my original post…sorry for the
confusion…the layout is still the exact same)
Thanks so much for your detailed response. I have been knocking away
at this since your post, with near-success. I am able to save new bom
(billofmaterial) records, and the invitem_id and component_id fields
are populating in the db with the appropriate id’s from the INVITEMS
table. But I am not able to use (for example, in my basic view for
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.name
Merely calling for:
…works fine though. Now, in looking around for a cause, I see that
invitem_type and component_type in the boms table are populating with
NULL. I know you mentioned… “The *_type fields are required for the
polymorphic association and handled my ActiveRecord, you dont have to
give any values…”. But, ROR is probably supposed to put something
in those field other than NULL, right? Something to do with the object
that is expected in invitem_id and component_id?
So I am trying to see where my error in the config is. I have:
class Bom < ActiveRecord::Base
belongs_to :invitem, :polymorphic => true
belongs_to :component, :polymorphic => true
class Invitem < ActiveRecord::Base
has_many :boms, :as => :invitem
has_many :boms, :as => :component
mysql> desc boms;
| Field | Type
| id | int(11)
| date_added | date
| invitem_id | varchar(20)
| invitem_type | varchar(20)
| component_id | varchar(20)
| component_type | varchar(20)
| qty | decimal(10,2)
| uom | varchar(5)
One question that pops to mind is, in my Bom.rb class, how does ROR
know what “belongs_to :component” does? Is that some under-the-cover
magic? Should I be expected to have a Component.rb somewhere? I don’t
necessarily want one…as “component” is only a field in the boms
table…and in reality “is an invitem”.
Could the fact that I am using “has_many :boms, :as => :invitem” be
causing conflict, as I actually have a class called Invitem? I know
the part “…:as => :invitem” is supposed to be an arbitrary name.
Hmmm? What might I be missing here?
Thanks so much for the response.