In Ruby on Rails, when you want to apply validation only under certain conditions, you can use with_options to group them nicely.
・Ruby on Rails Guides: Active Record Validations and Callbacks
・paramがなければModelのValidationをskipすれば良いじゃない #Ruby #Rails - Qiita
5.4 Grouping conditional validations Sometimes it is useful to have multiple validations use one condition, it can be easily achieved using with_options.class User < ActiveRecord::Base with_options :if => :is_admin? do |admin| admin.validates :password, :length => { :minimum => 10 } admin.validates :email, :presence => true end endAll validations inside of with_options block will have automatically passed the condition :if => :is_admin?
That’s all from the Gemba.