#137 ✓resolved

Validation documentation error

Reported by Daniel | July 7th, 2009 @ 05:46 PM

Hello Ben,

It seems that there is a discrepancy between the below two documentation pages in that one creates a "before_validation" callback, while the other creates a "validate" callback. In any case, I'm not having success with either version. When using "before_validation", "attempted_record" is nil. When using "validate", my method does not get called at all.


In the below example, nothing gets printed. Changing "validate" to "before_validation" prints the $s, but then throws a "nil object" error when reaching "if attempted_record.invited?" ("The error occurred while evaluating nil.invited?").

class UserSession < Authlogic::Session::Base
  logout_on_timeout true
  consecutive_failed_logins_limit 12
  validate :ensure_not_invited


def ensure_not_invited

puts &quot;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&quot;
if attempted_record.invited?
  puts &quot;********************************************&quot;

end end

Comments and changes to this ticket

  • Daniel

    Daniel July 9th, 2009 @ 04:29 PM

    After updating AuthLogic to version 2.1.1 from 2.0.14, validate :ensure_not_invited now causes ensure_not_invited to be called, but attempted_record is still nil.

  • Ben Johnson

    Ben Johnson July 12th, 2009 @ 09:35 PM

    • State changed from “new” to “resolved”

    You are right, but attempted_record could have the possibility of being nil. Checkout this code:

    def valid?
            self.attempted_record = nil
            new_session? ? before_validation_on_create : before_validation_on_update
            if errors.size == 0
              new_session? ? after_validation_on_create : after_validation_on_update
            errors.size == 0
            def ensure_authentication_attempted
              errors.add(:base, I18n.t('error_messages.no_authentication_details', :default => "You did not provide any details for authentication.")) if errors.empty? && attempted_record.nil?

    The validation chain will continue to be called regardless if attempted record is found or not. So if attempted_record is nil, that means the credentials passed could not locate a record. In your method you should check to see if attempted record is present before doing anything with it. If it is not present, there will be errors in the errors object.

    Validations have to occur this way for the magic fields and brute force protection. Ex: failed_logins_count.

    Hope that wasn't too confusing.

  • Daniel

    Daniel July 15th, 2009 @ 12:47 AM

    Thanks Ben. I was using valid login data, but perhaps because the object wasn't confirmed, the attempted_record stayed at nil. I was hoping to supersede the unconfirmed error with a different error, but at this point, I'm refactoring away from that need anyway, so it is no longer a problem for me.



  • Oepskson

    Oepskson September 7th, 2018 @ 06:34 AM

    knowledge Validation documents i have found here.

  • Nedich90
  • medtunisie
  • ritariya

    ritariya October 10th, 2018 @ 05:30 AM

    The documentation error is very common nowadays. It's only because of the lack of knowledge in the initiation procedures. I went through the description and i have followed it. I am glad that it works well. Thanks for the share. online computer repair

  • hendry

    hendry October 29th, 2018 @ 04:07 AM

    This article is about validation document error an example of a validation document code is mentioned here those who interested in this topic you can check it now. We can also add your corrections here.additional resources

  • Christopher987

    Christopher987 December 20th, 2018 @ 05:48 AM

    Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers provide common validation rules. Every time a validation fails, an error message is added to the object's errors collection, and this message is associated with the attribute being validated krogerfeedback.

  • lindarose11

    lindarose11 December 24th, 2018 @ 04:32 AM

    The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful
    Potty Racers 3

  • denis_richard

    denis_richard April 2nd, 2019 @ 09:00 AM

    You actually mentioned the possible solution of getting the error of Validation documentation. I think its a good platform where user can come and find out the solution of their problem. Infect, You need to take a look of https://itqna.net/questions/101213/input-validation-javascript because this website is actually like a mini search engine havine php, C++ related solutions of the errors. I found that site very valuable and it will be sound good for you as well.

  • marti birds

    marti birds April 8th, 2019 @ 02:09 PM

    The point on the was clear and the same thing is possible with Water slide rentals Houston

  • Jeff Danies

    Jeff Danies April 14th, 2019 @ 09:57 AM

    The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful Custom T Shirts Online India

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Object based authentication solution that handles all of the non sense for you. It's as easy as ActiveRecord is with a database.

People watching this ticket