Refactoring for rails 4