在特定的action里使用validates
2016-06-02 18:32
288 查看
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.
在特定的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
相关文章推荐
- 观察者模式
- [记录][续爬虫]模拟京东登录并且抢购物券
- C#对Excel表的读取和写入
- 新建一个CCS4.1项目及其文件配置
- ServletContextListener 解析用法
- Linux3:more、which、find、chmod、tar、diff、grep、ps、netstat、uname
- 单例模式
- https://jivoi.github.io/老外大神的两篇笔录
- 创建Oracle数据库、数据库名与实例名与SID之间的关系(图文详解)
- Linux2:vi、ls、cd、pwd、mkdir、rm、mv、cp、cat、tail
- Tomcat自带DBCP数据库连接池配置
- js、oc、html交互
- HTML5学习之FileReader new FormData()
- codeforces 431C DP
- 欢迎使用CSDN-markdown编辑器
- 使用CSS3美化复选框checkbox
- 别人的自定义控件的包复制到自己的工程时引用不到的情况
- HDU3499 Flight (两遍dijkstra)
- 轻松无痛苦学习CRC指南
- 使用TortoiseGit操作分支的创建与合并