Now, from all the research I am frantically doing, this seems like it
should work, but it doesn’t. I go into the console, find the first
GeneralMod, then do:
mod.GeneralModType = GeneralModType.new
mod.GeneralaModType.name = “blah”
mod.save
I get a saved mod type, but general_mod_type_id is still nil. I’ve got
another relationship in another two classes that’s working fine, so
I’m guessing I’m just screwing up something basic here. This is a
little higher level than I am used to, being a PHP schlub.
That said, I’ve been doing not too bad but am stumbling over a basic
problem, probably a naming issue. Here’s the steup:
class GeneralModType < ActiveRecord::Base
has_and_belongs_to_many :GeneralMods
has_many :general_mods
end
class GeneralMod < ActiveRecord::Base
belongs_to :GeneralModType
belongs_to :general_mod_type
.integer
end
Now, from all the research I am frantically doing, this seems like it
should work, but it doesn’t. I go into the console, find the first
GeneralMod,
meaning:
mod = GeneralMod.find(:first)
yes?
then do:
mod.GeneralModType = GeneralModType.new
Huh? Your GeneralModType probably exists first in order for a
GeneralMod to belong_to it.
Any help?
You also don’t show your migration to CreateGeneralModTypes, but I
assume it is similar.
blah_type = GeneralModType.new(:name => ‘blah’)
blah_type.save # or use .create rather than .new
Ya, after I posted I realized I screwed up with the HABTM thing, and
changed it back to has_many, but still using the camel case.
I tried it with the camel case first and got weird results and then
changed it to the lower case variant you supplied and it’s all working
now. What was happening there? Obviously it didn’t like camel case
there, but it was sort of working… Not quite all the way, but sort
of.
Thanks much anyway Rob.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.