No, this isn't a post about the much loved model-view-controller pattern. It's just a heads up to say that from today I'll be posting rails and ruby related snippets over on a tumblelog hosted by Tumblr rather than here on teamaskins. I've wanted to keep this stuff separate for sometime, but never had the spare time to setup a new blog. The guys at Tumblr have made it really simple to get started and let you host your blog under a custom domain name, so from now on you'll find my ruby ramblings at subrosa.teamaskins.net.
Here on teamaskins we'll return to puppy photos and inane rants about all sorts of whatnots. So, if you've been fond of my rails related posts grab the subrosa feed. And unless you want to hear about what I'm having for lunch tomorrow, you might want to unsubscribe from teamaskins.net.
Peace.
The latest post on Err The Blog reminded me of some alias_method_chain love I added to an ongoing project.
Ever mournful of the lack of a validate_on_destroy callback, I generated a plugin that implements one of my own.
class ActiveRecord::Base
class ObjectNotDestroyable < ActiveRecord::ActiveRecordError
end
def destroy_with_validation
validate_on_destroy if self.respond_to? :validate_on_destroy
unless errors.empty?
errors.add_to_base(
"#{self.class.name.titleize} could not be deleted"
)
raise ObjectNotDestroyable
end
destroy_without_validation
end
alias_method_chain :destroy, :validation
end
Super simple, and easy to use. Just add a callback as follows to your model.
def validate_on_destroy
unless self.some_problem?
errors.add_to_base(
"I don't think you really want to delete this baby!"
)
end
end
The ease with which I could implement this really makes me appreciate working with Ruby and Ruby on Rails.

Taken at the Australian Museum, Sydney.