check attributes.has_key? instead of object index to work with rails 4