首页 > 其他 > 详细

在特定的action里使用validates

时间:2016-06-02 19:54:46      阅读:138      评论:0      收藏:0      [点我收藏+]

 

http://guides.rubyonrails.org/v3.0.8/active_record_validations_callbacks.html#on

在特定的action里使用validates

The :on option lets you specify when the validation should happen. The default behavior for all the built-in validation helpers is to be run on save (both when you’re creating a new record and when you’re updating it). If you want to change it, you can use :on => :create to run the validation only when a new record is created or :on => :update to run the validation only when a record is updated.

 

class Person < ActiveRecord::Base
  # it will be possible to update email with a duplicated value
  validates_uniqueness_of :email, :on => :create
 
  # it will be possible to create the record with a non-numerical age
  validates_numericality_of :age, :on => :update
 
  # the default (validates on both create and update)
  validates_presence_of :name, :on => :save
end

 

在特定的action里使用validates

原文:http://www.cnblogs.com/iwangzheng/p/5554057.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!