Adapted for rails 4