在源文件中看到新的写法 和前面相差很多, 不过老方案在rails3也不会出错
Examples of using the default rails validators:
validates :terms, :acceptance => true
validates :password, :confirmation => true
validates :username, :exclusion => { :in => %w(admin superuser) }
validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create }
validates :age, :inclusion => { :in => 0..9 }
validates :first_name, :length => { :maximum => 30 }
validates :age, :numericality => true
validates :username, :presence => true
validates :username, :uniqueness => true
validates :title, :presence => true, :uniqueness => true, :length => { :maximum => 100 }
validates :budget, :presence => true, :length => { :within => 1..10000000 }
# Finally, the options :if, :unless, :on, :allow_blank and :allow_nil can be given
# to one specific validator:
#
validates :password, :presence => true, :confirmation => true, :if => :password_required?
感觉比原来的写起来越简单 一个属性的验证方案定义在一起
分享到:
相关推荐
NULL 博文链接:https://hlee.iteye.com/blog/587006
Rails3教程系列 DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY...
Rails 3 in Action 2011年9月新鲜出炉,针对最新的Rails 3.1进行说明
Devise - 一个基于Warden的Rails灵活身份验证解决方案
Windows7_Cygwin_Git_RVM_Ruby1.9.3_Rails3_MongoD B_Nginx_Unicorn_Rspec_Guard_Spork(2-Ruby on Rails3 安装配置
Ruby+on+Rails+3+Tutorial.pdf 应用Rails进行敏捷Web开发第4版.pdf (Agile Web Development with Rails) Rails.Recipes.Rails.3.Edition.pdf
Rails3消息队列系统 Sidekiq
turbo-sprockets-rails3, 加速你的Rails 3资产 用于 Rails 3.2.x的涡轮链轮 通过只根据源文件的哈希来重新编译已经更改的资产,从而加快 Rails 3 rake assets:precompile的速度只编译一次以生成指纹和非打印的资产...
rails3的英文文档
Rails3的ActiveRecord 查询API.doc
rails常用命令,例如新建rails项目,新建controller、model 等等
The Rails™ 3 Way is a comprehensive resource that digs into the new features in Rails 3 and perhaps more importantly, the rationale behind them. —Yehuda Katz, Rails Core The Bible for Ruby on ...
The Rails™ 3 Way is the only comprehensive, authoritative guide to delivering production-quality code with Rails 3. Pioneering Rails expert Obie Fernandez and a team of leading experts illuminate ...
Knock - 为Rails API实现无缝JWT身份验证
knock, 用于 Rails API的无缝JWT身份验证 敲门 用于 Rails API的无缝JWT身份验证描述敲门是 Rails api的认证解决方案,基于JSON网络令牌的应用程序。什么是JSON网络令牌? :为什么要使用这里选项?它是轻量级的。它...
ruby on rails开发的初学者很适合的工具书,易上手,很实用,
ruby on rails最新版 这是本人精心收集的重要软件
基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip ...