RailsアプリケーションをRails2.3.8からRails3.2.7にアップグレードしたところ、Activerecordで問題が発生しました。
Activerecord(例:Employee.last)を使用してデータベースにアクセスしようとすると、次のエラーが発生します。
NoMethodError: undefined method `accept' for nil:NilClass
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:38:in `find_by_sql'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/explain.rb:40:in `logging_query_plan'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:37:in `find_by_sql'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation.rb:171:in `exec_queries'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation.rb:160:in `to_a'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/explain.rb:33:in `logging_query_plan'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation.rb:159:in `to_a'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation/finder_methods.rb:378:in `find_first'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation/finder_methods.rb:122:in `first'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation/finder_methods.rb:336:in `find_one'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation/finder_methods.rb:107:in `find'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:5:in `__send__'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:5:in `find'
Rails3.2.7とRuby1.8.7を使用しています。以前はmysql2.7バージョンを使用していましたが、アップグレード時にエラーが発生したため、現在はmysql2(0.311)とactiverecord-myql2-adapter(0.0.3)を使用しています。
問題はこれに似ているようです:
Rails 3:Model.all => NoMethodError:nil:NilClassの未定義のメソッド'accept'
しかし、そこで提示されたすべてのソリューションを試しましたが、どれも機能しませんでした。
編集:'activerecord-mysql2-adapter' gemを取り出すと、代わりに次のエラーが発生します。
Address Load (0.7ms) SELECT `addresses`.* FROM `addresses` LIMIT 1
NoMethodError: undefined method `generated_methods?' for #<Class:0x7f10733eb2e8>
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/markos_validates_timeliness-2.3.2.2/lib/validates_timeliness/active_record/attribute_methods.rb:46:in `define_attribute_methods'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/attribute_methods.rb:168:in `respond_to?'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activesupport-3.2.7/lib/active_support/callbacks.rb:398:in `__run_callback'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activesupport-3.2.7/lib/active_support/callbacks.rb:385:in `_run_find_callbacks'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activesupport-3.2.7/lib/active_support/callbacks.rb:81:in `send'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activesupport-3.2.7/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/base.rb:523:in `init_with'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/inheritance.rb:68:in `instantiate'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:38:in `find_by_sql'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:38:in `collect!'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:38:in `find_by_sql'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/explain.rb:40:in `logging_query_plan'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:37:in `find_by_sql'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation.rb:171:in `exec_queries'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation.rb:160:in `to_a'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/explain.rb:33:in `logging_query_plan'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation.rb:159:in `to_a'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation/finder_methods.rb:378:in `find_first'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/relation/finder_methods.rb:122:in `first'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:5:in `__send__'
from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/querying.rb:5:in `first'