I thought I had a handle on this one but it’s causing me grief and I’m
hoping somebody can set me straight. I have an object AlertTemplate
which will contain a fill in the blank style hunk of web content. I
then have an object, Alert, which will have a relationship to one of
those AlertTemplate objects, plus some data.
So, in human speak, I’d think that an Alert has_one AlertTemplate. But
I can’t really say that AlertTemplate belongs_to Alert, because each
template may be used by many alerts. So AlertTemplate just as an id
column, but Alert has a template_id column.
In my form for creating an alert I have:
collection_select(:alert, :template, (AlertTemplate.find :all), :id,
to produce a dropdown for choosing which template you want to associate
with the new Alert object.
However in my controller’s create method when I do an
I get an error :
ActiveRecord::AssociationTypeMismatch in AlertController#create
AlertTemplate expected, got String
All the stack trace tells me is that the error happens on the Alert.new
line. But that’s where I’m lost. Which code expected an AlertTemplate?
What String did it get?
Interestingly I tried an experiment in irb. I created an AlertTemplate
object t, then created an empty Alert a, and said a.template = t and
tried to save it. The Alert object got saved – but template_id
remained null. That leads me to believe that I’ve got me id fields