Skip to content

Instantly share code, notes, and snippets.

@cloudsben
Created July 26, 2016 11:39
Show Gist options
  • Save cloudsben/8369f65207ab27b239b407606644f6ff to your computer and use it in GitHub Desktop.
Save cloudsben/8369f65207ab27b239b407606644f6ff to your computer and use it in GitHub Desktop.

Revisions

  1. cloudsben created this gist Jul 26, 2016.
    14 changes: 14 additions & 0 deletions is_presence
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # 查询字段是否为验证字段,如果是验证字段返回 false 不是 返回 true
    def is_presence poi, field
    presence_fields = poi.constantize.validators.map do | v |
    if v.is_a? ActiveRecord::Validations::PresenceValidator
    v.attributes
    end
    end
    # 去 nil 并 二维转一维
    if presence_fields.compact.flatten.exclude?(field)
    return true
    else
    return false
    end
    end