This project is archived and is in readonly mode.
Validations' if blocks are run before any :on checks are made
Reported by jwkpiano1 | April 13th, 2011 @ 01:59 AM
In Rails 3, if you have both an :if block and an :on declaration
on the same validation, the :if block runs before the :on
declaration is checked. For example, in the following code:
validates_presence_of :blah, :on => :update, :if =>
lambda { |record| record.id == 4 }
the :if block is run even
if the context is a create.
This seems to be due to the following code in
activemodel/validations/callbacks.rb:
`def before_validation(*args, &block) options =
args.extract_options! if options.is_a?(Hash) &&
options[:on]
options[:if] = Array.wrap(options[:if])
options[:if] << "self.validation_context == :#{options[:on]}"
end set_callback(:validation, :before, *(args << options), &block) end`, where the check is added to the end of the options[:if] array, causing the check to run after the :if block.
Comments and changes to this ticket
-
laptopbatteries April 16th, 2011 @ 03:08 AM
rolex watches are very common in our Audemars Piguet Replicas lifes, there are quite several well known wrist watches brands, the majority Gucci Replicas of them are Swiss bands, Panerai Replicas ,and it is Omega Replicas unlikely, unless the replica watches 's owner is filthy rich and equally careless replica breitling with his, Even the highest quality, Some replica omega are believed to be to acquire luxury wrist that are Replica Concord founded of gold or platinum or other high priced materials. placing on these wrist fake rolex certainly will make us stand out from other Swiss Replica Watch people.Does everyone can afford these genuine, replica tag heuer Taking your or replica watch ? When should expensive replica watch uk , before you take your precious?
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>