Tuesday, August 24, 2010

Overriding ActiveRecord methods

I recently needed to delete a file along with an active record model, and I wasn't sure about overriding rails' ActiveRecord::Base#delete method, but the following code worked without a hitch in my model:

def delete
 File.delete( File.join( Rails.root, fyle.path ) )
 super
end

However, overriding the initialize method in the same way is not recommended unless you really know what you are doing.

No comments:

Post a Comment