Isn't there a method in rails to do this?