Rails 3 和 ar_extensions:未定义的方法 attribute_condition
升级到 Rails 3 后,我的 Rails 应用程序中不断出现此错误。
>> u.sent_messages NoMethodError: undefined method `attribute_condition' for #Class:0x105523f18 from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/base.rb:1008:in `method_missing' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:79:in `sanitize_sql_from_hash' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `each_pair' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `sanitize_sql_from_hash' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:27:in `sanitize_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `send' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `sanitized_conditions' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_proxy.rb:105:in `conditions' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:103:in `construct_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_collection.rb:24:in `initialize' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:11:in `initialize' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `new' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `sent_messages' from (irb):36 from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:488
结果我仍在使用 中的 ar_extensions Gem http://www.continuousthinking.com/tags/arext。一方面,他们有一个后继者,另一方面,ActiveRecord 中现在有一个批量插入选项,可能值得检查(使用 Model.create([hash1, hash2, hash3, ...]))。
I kept getting this error in my Rails app after upgrading to Rails 3.
>> u.sent_messages NoMethodError: undefined method `attribute_condition' for #Class:0x105523f18 from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/base.rb:1008:in `method_missing' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:79:in `sanitize_sql_from_hash' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `each_pair' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `sanitize_sql_from_hash' from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:27:in `sanitize_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `send' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `sanitized_conditions' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_proxy.rb:105:in `conditions' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:103:in `construct_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_collection.rb:24:in `initialize' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:11:in `initialize' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `new' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `sent_messages' from (irb):36 from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:488
Turns out I was still using the ar_extensions Gem from http://www.continuousthinking.com/tags/arext. For one thing they have a successor, for another there is a bulk insert option in ActiveRecord now which might be worth checking out (using Model.create([hash1, hash2, hash3, ...])).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ar-extensions 仅适用于 Rails 2.x。对于 Rails 3.x,您应该使用 activerecord-import gem。它具有相同的导入 API。
https://github.com/zdennis/activerecord-import
ar-extensions is only for use in Rails 2.x. For Rails 3.x you should use the activerecord-import gem. It has the same import API.
https://github.com/zdennis/activerecord-import