Sorry, I am a bit behind.

OK, so the problem is
Because before_save changed the data stored in the data base, the
record xxx-xxx... looks different from xxxxxx in the database, to the
validation.

validates_uniqueness_of :credit_card, :if => :before_save, :message =>
"The credit card number already exists"
:if - Specifies a method, proc or string to call to determine if the
validation should occur (e.g. :if => :allow_validation, or :if =>
Proc.new { |user| user.signup_step > 2 }). The method, proc or string
should return or evaluate to a true or false value.
http://ar.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html

So with this :if condition,  before_card is called before the
validation,  returns "true", and then the validation is called.

I found this an interesting test example
http://dev.rubyonrails.org/ticket/7377

their conclusion is to use a call back before validation instead of
before_save and before_create.

It was interesting that with the :if => before_save condition present,
but no "before_save" method defined,
the before_validation never runs.

Did I get the point of the exercise or is there more I need to get?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to