I\'m learning Rails following the book Agile Web Development with Rails 4 and I got stuck with this Error:
NoMethodError in CartsController#destroy
undefined met
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.