I have a custom validation method that I only want executed on create:
validate :post_count, :on => :create
def post_count
# validate stuff
end
However, it's getting fired on update (in addition to on create).
Does the :on => :create
option not work with custom validation methods?
As far as I know, there's no :on
option. Use
validate_on_create :post_count
instead. And there's validate_on_update
also. You can read about this methods here.
This may be a Rails 2.x vs. Rails 3 issue but according to the Rails Guides on Validation the :on
option is definitely valid (though I am fighting with why it's not firing for me in a similar way).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With