Rails .save falhando silenciosamente? Os retornos implícitos de Ruby podem ser o seu problema.

Digamos que você tenha um modelo Blah que tem alguns valores que você deseja definir como falso por padrão. Se você fizer isso em um retorno de chamada, poderá ver falhas silenciosas à esquerda e à direita. Corrija assim:

class Blah < ActiveRecord::Base
after_create
:send_blah_email
before_save
:default_values

def default_values
self.smart ||= true
self.dumb ||= false
# remember - this is important, because ruby returns the last statement (in this case, false)
return true
end

def send_blah_email
BlahMailer.blah_notifier(self).deliver
#if blah mailer isn't essential, you can do this to make sure things still work out.
return true
end
end
```ruby

It's very easy to think, by default, that these callbacks shouldn't be keeping things from happening, but should just work. But, Ruby's implicit return makes the callback return false, which makes the whole call stack return false without actually saving the record. Oh, and no errors are attached to the model, either. (Hence the silent part.)



**Pro Tip**

Of course, you can have a little fun and return some fun string (or anything that doesn't evaluate to false).