added some code from rails 3 app