Hey all
I have a line of code that's causing a "undefined method `include?' for nil:NilClass" exception, but i can't work out what's actually going wrong with it. After a bit of experimentation i discovered that it's caused by simply asking for the id of an AR object i have.
ldb "question.id = #{question.id}"
ldb is just a logging method i have - it's not the problem as i got the same error initially when i tried to use question.id in a find call. Here's the line with some other logging output and the stack trace:
ldb "options = #{options.inspect}"
ldb "question = #{question.inspect}"
ldb "question.id = #{question.id}"
stack trace and debug logger output:
### ./app/models/quiz.rb:458:in `auto_generate_quizzes_from_questions': options = {:age_group_id=>3, :style=>"sequential", :tag=>#<Tag id: 60, name: "speaking", created_at: nil>, :size=>6}
### ./app/models/quiz.rb:459:in `auto_generate_quizzes_from_questions': question = #<Question id: 619, text: "Which of these words has only one syllable?", kind: "text", media_instruction_text: nil, qid: "619", editor_id: 22, editor_name: "Ian McNeilly", user_id: 15, author_ext_id: "22", original_target_age: "11", qtype: "Curriculum", keywords: "--- \n- Curriculum\n- English\n- School\n- Which\n- has\n...", created_at: "2010-02-25 13:20:02", updated_at: "2010-04-01 16:17:03", checked: false, subject_id: 1, official: nil, privacy: 1>
NoMethodError (undefined method `include?' for nil:NilClass):
lib/core_extensions.rb:6:in `method_missing'
app/models/quiz.rb:460:in `auto_generate_quizzes_from_questions'
app/models/quiz.rb:456:in `each'
app/models/quiz.rb:456:in `auto_generate_quizzes_from_questions'
app/controllers/admin/subjects_controller.rb:9:in `make_quizzes'
vendor/plugins/haml/rails/./lib/sass/plugin/rack.rb:44:in `call'
/usr/lib/ruby/1.8/mongrel/rails.rb:76:in `process'
/usr/lib/ruby/1.8/mongrel/rails.rb:74:in `synchronize'
/usr/lib/ruby/1.8/mongrel/rails.rb:74:in `process'
/usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
/usr/lib/ruby/1.8/mongrel.rb:158:in `each'
/usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
/usr/lib/ruby/1.8/mongrel.rb:285:in `run'
/usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
/usr/lib/ruby/1.8/mongrel.rb:285:in `new'
/usr/lib/ruby/1.8/mongrel.rb:285:in `run'
/usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
/usr/lib/ruby/1.8/mongrel.rb:268:in `new'
/usr/lib/ruby/1.8/mongrel.rb:268:in `run'
/usr/lib/ruby/1.8/mongrel/configurator.rb:282:in `run'
/usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `each'
/usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `run'
/usr/lib/ruby/1.8/mongrel/command.rb:212:in `run'
Line 460 is the last one listed above. I can see from the debug output above that question is a regular AR object.
The weird thing about this is that it always works first time after mongrel restart and fails every subsequent time. If i set config.cache_classes to true then it never happens - ie, it only starts happening after the class is reloaded, but doesn't happen when the class is first loaded.
kind of stumped - any ideas anyone? Even some advice on how to dive deeper and work out what's going on would be appreciated.
thanks, max