adapted for rails 4