I was getting this:

undefined method `to_f’ for {}:HashWithIndifferentAccess

This was happening in the after_create method. We have a table that lists fields and what validation is needed, we use this to pick out the value in the record so we can apply the validation function to the value if one has been given.

field_value = self.send(field_name) # Error was thrown here

I fixed this by calling self.reload at the beginning of the method that does the field scanning. I think that ActiveRecord does’t refresh its attributes hash after save and the error came from it expecting the value to be of a particular type… I don’t like calling reload, but can’t find a method that will refresh the attributes hash.

Bootnote

Discovered that this was the result of sending nils in the hash passed into the create method, as it came over the wire as XML and was then incorporated into the params array, unlike the conventional post method, which puts empty strings in there. I wrote a one-liner to remove the hash elements with nil in them and everything started working. There was also another nasty bug which was putting the HashWithIndifferentAccess thang into any empty strings.

params.delete_if{ |k,v|  v.blank? }