Hi all !
I’ve written a Character model, each character has many Attributes. My
schema.rb looks like this:
create_table “characters”, :force => true do |t|
t.string “first_name”
t.string “last_name”
t.integer “user_id”
t.datetime “created_at”
t.datetime “updated_at”
end
create_table “attributes”, :force => true do |t|
t.string “name”
t.float “value”
t.integer “character_id”
t.datetime “created_at”
t.datetime “updated_at”
end
And the models look like this:
class Character < ActiveRecord::Base
has_many :attributes
…
end
class Attribute < ActiveRecord::Base
belongs_to :character
end
When I want to create a new instance by calling
c = Character.new :first_name => “hello”, :last_name => “world”
I get this Error:
ActiveRecord::AssociationTypeMismatch: Attribute(#17724630) expected,
got Array(#104100)
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
associations/association_proxy.rb:214:in raise_on_type_mismatch' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ associations/association_collection.rb:229:in
replace’
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
associations/association_collection.rb:229:in each' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ associations/association_collection.rb:229:in
replace’
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
associations.rb:1149:in attributes=' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2130:in
initialize’
from (irb):1:in `new’
from (irb):1
from :0
I have no idea why I get this error, since I don’t specify the
“attributes” key. I hope you can help me, thank you very much in
advance.
Greetings,
Christoph