Object.destroy генерирует ArgumentError: неправильное количество аргументов (1 вместо 0)

У меня есть простая модель, где

class User < ActiveRecord::Base
  has_many :comments, dependent: :destroy
  has_many :answers, dependent: :destroy
end

Когда я пытаюсь удалить с помощью User.first.destroy (на консоли), я получаю: ArgumentError: неправильное количество аргументов (1 вместо 0).

Детали:

u.destroy
Comment Load (0.2ms)  SELECT "comments".* FROM "comments" WHERE "comments"."user_id" = 4
SQL (14.6ms)  DELETE FROM "comments" WHERE "comments"."id" = ?  [["id", 4]]
SQL (0.1ms)  DELETE FROM "comments" WHERE "comments"."id" = ?  [["id", 5]]
SQL (0.0ms)  DELETE FROM "comments" WHERE "comments"."id" = ?  [["id", 6]]
ArgumentError: wrong number of arguments (1 for 0)
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/bullet-2.1.0/lib/bullet/active_record31.rb:88:in `has_cached_counter?'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/has_many_association.rb:61:in `update_counter'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/has_many_association.rb:90:in `delete_records'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/collection_association.rb:452:in `block in    delete_or_destroy'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/collection_association.rb:147:in `block in transaction'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/transactions.rb:208:in `transaction'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/collection_association.rb:146:in `transaction'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/collection_association.rb:449:in `delete_or_destroy'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/collection_association.rb:220:in `delete'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/collection_association.rb:155:in `delete_all'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/collection_proxy.rb:54:in `delete_all'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/associations/builder/has_many.rb:42:in `block in   define_destroy_dependency_method'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:395:in `_run_destroy_callbacks'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/callbacks.rb:254:in `destroy'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/transactions.rb:236:in `block in destroy'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in  `transaction'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/transactions.rb:208:in `transaction'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/activerecord-3.1.3/lib/active_record/transactions.rb:236:in `destroy'
from (irb):2
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/matreyes/.rvm/gems/ruby-1.9.3-p0@curso/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Мне нужна помощь .. я пытался в течение нескольких часов Спасибо!


person matreyes    schedule 21.03.2012    source источник


Ответы (2)


Камень bullet кажется проблемой. Посмотрите на первую строку вашей трассировки стека. Проблема заключается в этом методе. Вероятно, это вызов origin_has_cached_counter?, на который он жалуется.

person Ryan Bigg    schedule 21.03.2012
comment
Спасибо! Я не помнил, что пуля была установлена ​​мной ... и я думал, что это ошибка ядра рельсов. - person matreyes; 22.03.2012

Вы забыли => в своей модели и поставили :, которого там не должно быть ;) Должно быть так:

class User < ActiveRecord::Base
  has_many :comments, :dependent => :destroy
  has_many :answers, :dependent => :destroy
end
person Sylvain Desbureaux    schedule 22.03.2012
comment
нет, все в порядке. В ruby ​​1.9 dependent: такой же, как :dependent => Проблема была в пуле гема, теперь все работает. Спасибо. - person matreyes; 22.03.2012