transplant from Rails ver4