zoukankan      html  css  js  c++  java
  • 在特定的action里使用validates

    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
  • 相关阅读:
    服务器
    python的并发编程学习
    python的网络编程学习
    python的基础学习 模块
    pymysql基础操作
    查询简单练习
    数据准备
    数据库的三大设计范式
    数据库基础-建表约束
    mysql基础-基本语法
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/5554057.html
Copyright © 2011-2022 走看看