NoMethodError in CartsController#destroy - Agile Web Development with Rails 4

喜夏-厌秋 提交于 2019-12-02 02:26:20

Tried from rails console and got this:

2.2.0 :001 > carro = Cart.find(25)
  Cart Load (12.9ms)  SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1  [["id", 25]]
 => #<Cart id: 25, created_at: "2015-02-17 01:10:49", updated_at: "2015-02-17 01:10:49"> 
2.2.0 :002 > carro.destroy
   (0.2ms)  begin transaction
/home/xx/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:75: warning: circular argument reference - reflection
/home/xx/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:79: warning: circular argument reference - reflection
/home/xx/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:83: warning: circular argument reference - reflection
/home/xx/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:102: warning: circular argument reference - reflection
  LineItem Load (0.2ms)  SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = ?  [["cart_id", 25]]
  SQL (0.3ms)  DELETE FROM "line_items" WHERE "line_items"."id" = ?  [["id", 116]]
  SQL (0.1ms)  DELETE FROM "line_items" WHERE "line_items"."id" = ?  [["id", 117]]
  SQL (0.1ms)  DELETE FROM "line_items" WHERE "line_items"."id" = ?  [["id", 118]]
   (0.2ms)  rollback transaction
NoMethodError: undefined method `name' for nil:NilClass
    from /home/xx/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:80:in `cached_counter_attribute_name'

What happens is that /home/xx/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:75: warning: circular argument reference - reflection is caused for a bug in activerecord according to this GitHub issue.

What I did was update the rails version. I was using rails 4.0.0, after updating to rails 4.1.2 the problem was solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!