我before_filter
的一个控制器中有这个:
def valid_people
person_ids = params[:project][:person_ids]
if person_ids.present?
person = current_user.people.where("id IN (?)", person_ids).to_a
redirect_to(root_path) unless person
end
end
第 4 行检查数组中ids
的所有person_ids
元素是否都包含在用户的people
.
但是,如果不是这种情况,它会引发错误。
我怎样才能让第 4 行返回nil
?
谢谢你的帮助。