#146 ✓moved_to_github
maurizio.demagnis (at gmail)

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:

class UserSession

validate :check_if_awesome

  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?


that I've adapted into this:

class UserSession < Authlogic::Session::Base

validate :check_if_user_enabled

    def check_if_user_enabled
#        User.find_by_login(object.login).enabled


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

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.