Note that there are some explanatory texts on larger screens.

plurals
  1. POFind or create by field doesnt work
    text
    copied!<p>Ive got a model caleld SpacialBody, and I need to seed some records so first off I added this to my seeds.rb</p> <pre><code>[ ["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 </code></pre> <p>and this produced an error. I then went into console to test the code and found that this happened:</p> <blockquote> <blockquote> <p>SpacialBody.new => # SpacialBody.find_by_name("Sol") => nil SpacialBody.find_or_create_by_name("Sol") NoMethodError: undefined method <code>generated_methods' for nil:NilClass from /var/lib/gems/1.8/gems/activesupport-2.3.8/lib/active_support/whiny_nil.rb:52:in</code>method_missing' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:356:in <code>respond_to?' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in</code>assign_attributes' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in <code>each' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in</code>assign_attributes' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2775:in <code>attributes=' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1965:in</code>send' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1965:in <code>find_or_create_by_name' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2475:in</code>initialize' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1963:in <code>new' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1963:in</code>find_or_create_by_name' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1975:in <code>send' from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1975:in</code>method_missing' from (irb):3</p> </blockquote> </blockquote> <p>Ive used find_or_create_by_field in other projects without incedent, and i cant see anything different in my setup here.</p> <p>Its only this model that has the problem, others in the same project work fine.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload