Refactor js and rails