#126 ✓moved_to_github
German Monfort

Using authlogic with STI User models

Reported by German Monfort | June 18th, 2009 @ 02:48 AM

Using authlogic with models that extend the User class (using Single Table Inheritance)
seems to break things since you end up with nil objects for @current_user in your controllers

class User < ActiveRecord::Base
     acts_as_authentic
end
class NormalUser < User;end
class SpecialUser < User;end

Is it possible to use authlogic with STI?

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson June 20th, 2009 @ 04:40 AM

    • State changed from “new” to “open”

    I'm not sure, but I dont think it would be difficult to support. What are the specific errors?

  • Vann

    Vann July 8th, 2009 @ 11:52 AM

    I'm using authlogic with STI right now and everything seems to work fine under development, but when I run it in production mode and attempt to update a model, this is what I get:

    NoMethodError (undefined method `=' for #<Patient:0xb34032c>):
    authlogic (2.1.1) [v] lib/authlogic/acts_as_authentic/password.rb:229:in `send'
    authlogic (2.1.1) [v] lib/authlogic/acts_as_authentic/password.rb:229:in `password='
    

    Here's the current setup for the models:

    class User < ActiveRecord::Base
      acts_as_authentic
    end
    class Patient < User;end
    class Doctor < User;end
    

    I looked at the password method, but I'm not sure what is happening or what to look for, is authlogic actually passing the whole model to the password method. Any help would be much appreciated.

    Thanks!
    - Vann

  • Ben Johnson

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

    It looks like:

    Patient.crypted_password_field

    Is returning nil. What does Patient.column_names return for you?

  • Vann

    Vann July 12th, 2009 @ 10:27 PM

    Here's what it returns:

    >> Patient.column_names

      Patient Columns (3.2ms)   SHOW FIELDS FROM `users`
      => ["id", "login", "name", "email", "crypted_password", "salt", "created_at",   "updated_at", "remember_token", "remember_token_expires_at", "first_name", "last_name", "ssn", "address", "city", "state", "zip", "drivers_license", "home_phone", "cell_phone", "fax", "employer", "insurance_co", "insurance_type", "insurance_id", "allergies", "medications", "operations", "chronic_conditions", "family_history", "immunizations", "visits_count", "appointments_count", "login_count", "getting_started", "type"]
    
  • Ben Johnson

    Ben Johnson August 7th, 2009 @ 06:20 PM

    • State changed from “open” 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.

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

Tags

Pages