Skip validation when this_action

How can I write a condition in a validation that will skip validation if
it comes from a certain action?

:if => don't_validate_when_this_action

Or how do you handle this, with validation, when you have an update form
that are for updating certain fields/columns?

The model has no idea what action has caused it to be validated.
Either call save(false) which skips all validations, or let the model
know (eg have an instance variable which indicates which validations
can be skipped)

Fred

Frederick Cheung wrote:

not sure what you mean there.

Fred

Frederick Cheung wrote:

still a bit confusing.

Do you mean save as if I use a @object.save in the update action?

Is this the right way to write it?

def update
@object = Object.find(id)
@object.update_attributes(params[:object])
@object.save(false)

Not quite - update_attributes does the save for you, so this will save
twice (although the update_attributes might fail because of the
validation)
@object = Object.find(id)
@object.attributes = params[:object]
@object.save(false)

Should do the trick

Fred