
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.
http://rdoc.info/rdoc/binarylogic/authlogic/blob/aa4ee71622b151f3a2...
http://rdoc.info/rdoc/binarylogic/authlogic/blob/aa4ee71622b151f3a2...
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
private
def ensure_not_invited
puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
if attempted_record.invited?
puts "********************************************"
self.errors.clear
self.errors.add_to_base('invited_but_not_created')
end
end
end
Comments and changes to this ticket
-
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? errors.clear self.attempted_record = nil before_validation new_session? ? before_validation_on_create : before_validation_on_update validate ensure_authentication_attempted if errors.size == 0 new_session? ? after_validation_on_create : after_validation_on_update after_validation end save_record(attempted_record) errors.size == 0 end private 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? end
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.
-
jacknoname February 23rd, 2021 @ 01:13 AM
เราเป็นผู้ให้บริการที่มีตัวเกมสล็อตให้เลือกเล่นจำนวนมากเพราะเรามีการพัฒนาเกมใหม่ๆเพื่อเอาใจและตอบสนองความต้องการของผู้เล่นตลอดอยู่ตลอดเวลาเราได้เลือกเกมสล็อตยอดนิยมจากผู้เล่นมาส่วนหนึ่งเพื่อเป็นแนวทางสำหรับผู้เล่นเกมหน้าใหม่หรือเพื่อเปิดประสบการณ์ให้กับผู้เล่นเกมสล็อตเก่าๆที่อาจจะกำลังมองหาเกมสล็อตใหม่ๆเล่นเราจึงมีเว็บที่ดีที่สุดในตอนนี้มาแนะนำสนใจคลิ๊ก https://www.xosuperslot.com
https://www.xopgth.com/
https://xojoker.com/
https://www.xoautobet.com/
https://www.xogclubth.com/
superslot แจกเงินฟรี ทดลองเล่นเลย 50 บาท -
portiawilliams December 17th, 2021 @ 11:41 PM
Finding quality learning aids is most essential for gaining your dream grades in college. TestBanks21 offers Test Banks & Solution Manuals at the lowest prices online to satisfy this need.
https://testbanks21.com/ -
velmashackles December 21st, 2021 @ 05:11 AM
Finding quality learning aids is most essential for gaining your dream grades in college. TestBanks21 offers Test Banks & Solution Manuals at the lowest prices online to satisfy this need.
https://testbanks21.com/ -
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.
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.