Skipping validation during create?

Hi,

Is it possible to skip validation during create? During
update it exists: update_attributes_with_validation_skipping ?

Thanks,
Ram.

On 1/16/07, Ram [email protected] wrote:

Hi,

Is it possible to skip validation during create? During
update it exists: update_attributes_with_validation_skipping ?

I don’t know about skipping it when you call create, but if you do
model = Model.new params[:model]
model.save false

That’ll skip validations when it saves it, which ends up being the same
thing.

Pat

Ram wrote:

Hi,

Is it possible to skip validation during create? During
update it exists: update_attributes_with_validation_skipping ?

Thanks,
Ram.

Many of the validation methods accept an :on parameter which specifies
when the validation is to occur:

For example validates_numericality_of() accepts :on=>:save,
:on=>:create, :on=>update

Hope this helps…

ilan

validates_presence_of :on => :update

It works [I believe] for all the validations.

RSL

The above posts offer cleaner solutions.
But here’s what I used when I needed really fine tuned control of
validation.

I kept a sepearte column called “validate” or such.

then in the validate method

def validate
if self.validate?
… my validations …
end
end

I’d only set validate to true when I was ready to have validation.

Again, I think the above solutions are a lot cleaner.

Ram wrote:

Hi,

Is it possible to skip validation during create? During
update it exists: update_attributes_with_validation_skipping ?

Thanks,
Ram.

Hi all,

Thanks for the inputs ! The “:on” solution is nice and
simple although modifying-validate-action solution isn’t
bad either. Thanks again…

Ram.