changed conditions to work with rails 4