Ive got a model caleld SpacialBody, and I need to seed some records so first off I added this to my seeds.rb
[
["Sol",0,0,0,"standard"]
].each do |body|
nb=SpacialBody.find_or_create_by_name(body[0])
nb.name = body[0]
nb.x = body[1]
nb.y = body[2]
nb.type = SpacialBody::Types[body[3]]
nb.class = body[4]
nb.save
end
and this produced an error. I then went into console to test the code and found that this happened:
SpacialBody.new => # SpacialBody.find_by_name("Sol") => nil SpacialBody.find_or_create_by_name("Sol") NoMethodError: undefined method
generated_methods' for nil:NilClass from /var/lib/gems/1.8/gems/activesupport-2.3.8/lib/active_support/whiny_nil.rb:52:in
method_missing' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:356:inrespond_to?' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in
assign_attributes' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:ineach' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in
assign_attributes' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2775:inattributes=' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1965:in
send' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1965:infind_or_create_by_name' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2475:in
initialize' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1963:innew' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1963:in
find_or_create_by_name' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1975:insend' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1975:in
method_missing' from (irb):3
Ive used find_or_create_by_field in other projects without incedent, and i cant see anything different in my setup here.
Its only this model that has the problem, others in the same project work fine.