无法从轨道种子创建记录,失败并显示未定义的方法"generated_methods?



我最近将一个应用程序从rails 2.3.18升级到rails 3.2.1,我正试图完全迁移它。

当我运行rake db:seeds时,它失败了:

 undefined method `generated_methods?' for WhateverObject

这是一个非常基本的种子文件的内容:

[ 'MTW', 'GBP', 'USD', 'EUR' ].each do |currency|
  binding.pry
  Currency.find_or_create_by_code(currency)
end
通过pry,我注意到我不能调用任何方法,如:
Currency.new Currency.create

我还试过:

Currency.where(code: currency).first_or_create
Currency.column_names
=> ["id", "code", "rate"]

怎么了?

堆栈跟踪:

rake aborted!
NoMethodError: undefined method `generated_methods?' for Currency(id: integer, code: string, rate: decimal):Class
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/szilm-validates_timeliness-2.3.1/lib/validates_timeliness/active_record/attribute_methods.rb:46:in `define_attribute_methods_with_timeliness'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/attribute_methods.rb:168:in `respond_to?'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/attribute_assignment.rb:81:in `block in assign_attributes'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/attribute_assignment.rb:78:in `each'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/relation/finder_methods.rb:294:in `block in find_or_instantiator_by_attributes'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/base.rb:500:in `initialize'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/relation/finder_methods.rb:293:in `new'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/relation/finder_methods.rb:293:in `find_or_instantiator_by_attributes'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.21/lib/active_record/dynamic_matchers.rb:52:in `method_missing'
/home/bogdan/projects/%^&^*&/webapp/db/seeds/currencies.seeds.rb:4:in `block in <top (required)>'
/home/bogdan/projects/$%^%&*/webapp/db/seeds/currencies.seeds.rb:2:in `each'
/home/bogdan/projects/&^*&*&/webapp/db/seeds/currencies.seeds.rb:2:in `<top (required)>'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:245:in `load'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:245:in `block in load'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/bogdan/.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:245:in `load'
/home/bogdan/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/bogdan/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'

看来您的问题是由过时的validates_tim时效gem(您有2.3.1版本)引起的。

尝试升级到3.x版本:

在你的Gemfile

gem 'validates_timeliness', '~> 3.0'

,然后像往常一样运行:

$ bundle install

最新更新