Archive for the ‘Authlogic’ Category

Just a quick note on Authlogic and naming of the User and Session models.

Generally most people I assume use the name User for the user model and UserSession for the session information. I had this working and then decided the session information would be better described by the name LoginSession instead so went about renaming all the relevent classes/methods etc.

After this change Rails would return an error message of uninitialized constant Login whenever I tried hitting the login page. This is due to Authlogic’s default behaviour of  inferring the user class name from the session model name, in this case, Login from LoginSession.

To get around this use authenticate_with <classname> within your session model to tell Authlogic to authenticate against a different user model. i.e

authenticate_with User

Hopefully this will save someone else the time I spent working out why my app had broken through a simple name change.