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?

On Jun 20, 8:34 am, Pål Bergström [email protected]
wrote:

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

On 20 Jun 2008, at 10:46, Pål Bergström wrote:

Do you mean save instead of update_attributes?

How do I pick up that instance variable in the model? I can’t use
params[:variable], right? Is it :variable?
not sure what you mean there.

Fred

Frederick C. wrote:

On Jun 20, 8:34�am, P�l Bergstr�m [email protected]
wrote:

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

Do you mean save instead of update_attributes?

How do I pick up that instance variable in the model? I can’t use
params[:variable], right? Is it :variable?

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)
end

Frederick C. wrote:

On 20 Jun 2008, at 10:46, Pål Bergström wrote:

Do you mean save instead of update_attributes?

How do I pick up that instance variable in the model? I can’t use
params[:variable], right? Is it :variable?
not sure what you mean there.

Fred

Neither do I :slight_smile: I’ve been using Rails for a while now, but some stuff
is still a bit confusing.

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

On 20 Jun 2008, at 11:19, Pål Bergström wrote:

@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