当 id 不存在时,Model.find(id)
会抛出错误
大家更倾向于用哪种方式来解决比较好的?
1.@model = Model.find_by_id(id)
2.@model = Model.find(id) if Model.exists?(id)]
3.begin
@model = Model.find(id)
rescue ActiveRecord::RecordNotFound => e
@model = nil
end
4.其他?