Hello,
I'm having trouble debugging an override of destroy. I have an object that in some cases I need to send a parameter when I destroy it. Usually not though. So I've defined destroy in the model class like this:
class Look < ActiveRecord::Base belongs_to :palette
has_many :colorings, :dependent => :destroy has_many :colors, :class_name => 'SiteColor', :dependent => :destroy has_one :active_regatta, :class_name => 'Regatta' belongs_to :regatta
def destroy(options = {}) # special destroy so we don't accidentally default look protected_ids = [1]
super unless (protected_ids.include?(self.id) || options[:override] ) end end
The problem is that when I try to destroy one of these objects, I get an error on the call to super, "wrong number of arguments (1 for 0)" :
l=Look.find(62)
=> #<Look:0x23d2a28 @attributes={"name"=>nil, "id"=>"62", "palette_id"=>nil, "regatta_id"=>nil}>
l.destroy
ArgumentError: wrong number of arguments (1 for 0) from ./script/../config/../config/../app/models/look.rb:19:in `destroy' from ./script/../config/../config/../app/models/look.rb:19:in `destroy' from (irb):2
Note that there is a :has_many :dependent => :destroy relationship.
It seems that my call to super is getting arguments I don't know about, but I don't understand how to dig any deeper into this. I tried stepping into the call to super itself, and I immediately end up in the rescue clause for ActiveRecord's transaction method:
(rdb:1) where --> #0 /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:62 in 'transaction' (rdb:1) l = [57, 66] in /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb 57 transaction_open = true 58 end 59 yield 60 end 61 rescue Exception => database_transaction_rollback => 62 if transaction_open 63 transaction_open = false 64 rollback_db_transaction 65 end 66 raise
FWIW, I considered the possibility that it was one of the dependent relationships' objects who's destroy method was getting sent a parameter it wasn't expecting - so I defined both of those to accept a parameter as well, and then *their* call to super caused this problem.