
custom validation
Reported by maurizio.demagnis (at gmail) | August 5th, 2009 @ 06:49 AM
My User class has a boolean field named "enabled". I'd like to
prevent the login if that field is set to false. I found here an
example code:
http://rdoc.info/rdoc/binarylogic/authlogic/blob/72992b9effaea12f10...
class UserSession
validate :check_if_awesome
private
def check_if_awesome
errors.add(:login, "must contain awesome") if login && !login.include?("awesome")
errors.add(:base, "You must be awesome to log in") unless attempted_record.awesome?
end
end
that I've adapted into this:
class UserSession < Authlogic::Session::Base
validate :check_if_user_enabled
private
def check_if_user_enabled
debugger
# User.find_by_login(object.login).enabled
end
end
so, why does UserSession doesn't inherit from
Authlogic::Session::Base ?
Moreover, using the debugger I can't see the "errors" object, I can
only access to it by "object.errors".
so, if I'm not doing anything wrong, the problem in this ticket should only be about syncing this to the documentation.
Maurizio De Magnis
Comments and changes to this ticket
-
maurizio.demagnis (at gmail) August 5th, 2009 @ 06:57 AM
Shame on me, it seems that only in the debugger context "errors" and the other fields are accessible through "object"..
-
Ben Johnson August 7th, 2009 @ 06:20 PM
- State changed from new to moved_to_github
[state:"moved_to_github" bulk edit command]
-
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.