We spent a big chunk of yesterday hunting down a strange bug in one of
our rails apps and created a test project to try out different theories
on what was going on. The result so far is a very small test case app
that perfectly reproduces the problem. The question is, is there
anything *wrong* with what we're doing here, or is it a problem with
ActiveRecord? We're on rails 1.1.6 at the moment, so if this is a known
bug that's fixed in 1.2, just club me over the head with the trac reference.
IMVHO is always better not to play redefining such method like save.
Anyway I suspect sometime behind the scene the save method can be
passed an argument.
In your code the save method is defined that way
def save
gadget.save
super
end
so it won't accept any argument and will raise
ArgumentError: wrong number of arguments (1 for 0)
when 1 argument is passed.
I'd try to redefine the method this way
def save(*args)
gadget.save
super(*args)
end
I'm not 100% sure and you may need some further inspection, but really
smells like you've got this kind of problem.
HA! That's it. adding (*args) solved the problem instantly.
I agree that overriding the save was questionable, but there's a rather
complex series of things and conditions happening on save and at the
time this code was written, that was what worked for us. It wasn't
until yesterday that some other code caused this code to break, and our
wonderful tests identified the problem immediately, long before we
deployed the revision. Hooray for tests!