adapted to rails4