我刚刚将我的 Rails 应用程序从 Rails 2.3.8 升级到 Rails 3.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'
我正在使用带有 Ruby 1.8.7 的 Rails 3.2.7。我之前使用的是 mysql 2.7 版本,但升级时遇到错误,所以我现在使用 mysql2 (0.311) 以及 activerecord-myql2-adapter (0.0.3)。
问题似乎与此类似:
Rails 3:Model.all => NoMethodError:nil:NilClass 的未定义方法“接受”
但是我尝试了那里提供的所有解决方案,但没有一个奏效。
编辑:如果我取出 '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'