Optimize cook_rails cookbook codes