`

自定 validation与validates

    博客分类:
  • RUBY
 
阅读更多
validates :roles, presence: true
  #validates :innergroups, presence: true, :if => :need_roles_groups?
  validate :expiration

  def expiration
    unless self.roles.blank?
    self.roles.each do |role|
      roles = ['2','3','4','5','9']
      if roles.include? role
        if self.innergroups?
          if !self.innergroups[Role.find(role).name.to_s].present?
            errors.add(:innergroups, "不能为空 => [#{I18n.t(Role.find(role).name)}]")
          end
        else
          errors.add(:innergroups, "不能为空 => [#{I18n.t(Role.find(role).name)}]")
        end
      end
    end
    end
  end
分享到:
评论

相关推荐

    validates_url:Rails的URL验证

    ActiveRecord :: Base # standard validation validates :homepage , url : true # with allow_nil validates :homepage , url : { allow_nil : true } # with allow_blank validates :homepage , url : { allow_...

    validation-masterPHP数据验证库.zip

    }验证(Verification)是信息术语,编译过程的一部分,在该过程中,对代码进行检查,看是否与定义的特定规则集相一致,以允许检验某些安全要求。公共语言运行库可以验证Microsoft中间语言(MSIL)。服务器端验证就是当...

    validation_hints:验证提示

    validates :password , :length => { :within => 1 ... 5 } end Person . new . hints [ :name ] = > [ "can't be blank" ] Person . new . hints [ :password ] = > [ "must not be shorter than 1 characters" ...

    validates_formatting_of:包装在gem中的Common Rails验证

    validates_formatting_of gem添加了几种便捷的方法来验证Rails应用程序中的内容,例如电子邮件,URL和电话号码。 支持的Ruby版本 1.9.3 2.0.0 2.1.0 2.2.0 安装 要安装validates_formatting_of ,请将以下内容...

    kawaii_validation:一个ActiveRecord扩展,它添加了更多的kawaii验证语法

    安装宝石文件: gem 'kawaii_validation'然后执行: $ bundle支持的版本Ruby 2.0、2.1、2.2、2.3、2.4和2.5(主干) Rails 3.2.x,4.0、4.1、4.2、5.0、5.1和5.2(边缘)用法捆绑了该gem后, validates方法将采用...

    rspec_sequel_matchers:RSpec续集匹配器

    匹配器假定您正在使用推荐的validation_helpers插件。 支持所有实例验证方法,即: validates_exact_length validates_format validates_includes validates_integer validates_length_range validates_max_...

    NIST SP800-29.pdf

    On July 17, 1995, NIST established the Cryptographic Module Validation Program (CMVP) that validates cryptographic modules to Federal Information Processing Standard (FIPS) 140-1 Security Requirements...

    validates_timeliness:ActiveModel和Rails的日期和时间验证插件。 支持多个ORM,并允许自定义日期时间格式

    validates_timeliness:ActiveModel和Rails的日期和时间验证插件。 支持多个ORM,并允许自定义日期时间格式

    html5_validators:Rails 3,Rails 4,Rails 5和Rails 6的gemplugin,可使用ActiveModel + HTML5 Form Validation进行客户端验证

    产品特点PresenceValidator =>必填模型class User include ActiveModel :: Validations validates_presence_of :nameend 视图<%= f.text_field :name %> 其他text_field ish助手, text_area , radio_button...

    asp.net mvc

    When the required ASP.NET Ajax globalization scripts are included in a page, the validation logic uses the culture-specific data for data types (such as dates and numbers) when it validates input text...

    Bounds Checker6.01 for Delphi

    Active API checking This feature reduces your debugging time and provides peace of mind with the most comprehensive Windows API validation in the industry. The result for you is higher quality code ...

    activerecord-rescue_from_duplicate:Ruby gem从MySQL,PostgreSQL和Sqlite重复错误中解救出来

    它补充:validates_uniqueness_of ,并将添加适当的错误。 此外,宏允许您假定记录将是唯一的,否则将以优美的方式进行挽救。 经过测试: ActiveRecord:3.2、4.0、4.1、4.2,边缘 Ruby 1.9.3、2.0.0、2.1.2 ...

    TypeGuards:TS和JS的运行时类型检查库

    TypeGuard TypeScript和JavaScript的运行时类型检查库。 :sparkles: 特征提供运行时类型验证。... validates ( 1 ) // trueT . Number . validates ( '1' ) // falseT . Optional ( T . String ) . validates ( '1'

    valitron-masterPHP数据验证库.zip

     }验证(Verification)是信息术语,编译过程的一部分,在该过程中,对代码进行检查,看是否与定义的特定规则集相一致,以允许检验某些安全要求。公共语言运行库可以验证Microsoft中间语言(MSIL)。服务器端验证就是当...

    Aria2135032bit.7z

    Using Metalink's chunk checksums, aria2 automatically validates chunks of data while downloading a file like BitTorrent. The project page is located at https://aria2.github.io/. See aria2 On...

    swagger-cli:Swagger 2.0和OpenAPI 3.0命令行工具

    cli用法swagger-cli <command> [options] <file>Commands: validate Validates an API definition in Swagger 2.0 or OpenAPI 3.0 format bundle Bundles a multi-file API definition into a single fileOptions: -...

    Delphi7.1 Update

    Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main ...

Global site tag (gtag.js) - Google Analytics