Can I change the verification rules required for different actions?

I have a model that looks like this:

class Car < ActiveRecord::Base
  validates :name,:presence =>true
end

Can I configure it so that the machine name is not required when preparing the create operation, but is it necessary when performing the "change" action?

+5
source share
1 answer

Yup, this is possible:

class Car < ActiveRecord::Base
  validates :name, presence: true, on: :update
end

You can take a look at Active Records and Callbacks .

+7
source

All Articles