Refactor for rails4