views:

134

answers:

1

Hello,

While playing around with Rails (since I am a newbie) while reading Agile Rails book I came across an issue using the Gem Authlogic that I don't know how to address.

I have a simple business Model. The tables store the following information: Name, Address, Latitude, and Longitude.

The above approach has been working fine, because using the console I can enter the information and it shows up, where I need it to.

My issue now is that I want to add authentication to it. As in assign those records in the table, to individual accounts. Since Authlogic is an authentication gem, can this be done?

What I am trying to get to here is that, I enter a few records and leave it at that. Few days later, I want to assign those individual rows in the table to an authlogic model so the person to whom the record should belong can authenticate to it and make changes.

Any code samples, blog posts to better help me understand would be great!

Thank You.

A: 

Authlogic will create a model called users. Let's say your model is called persons. You add a user_id field to your persons model and link them by association:

class Person belongs_to :user end

class User has_one :person end

Thank you for the response. Using the association, I would assume that I will be able to login using the UserSession controller without any issues. Am I right path?Ex Scenario: Persons model has a field called "name", using the UserSession Controller, I should be able to login and change that "name" field for any user I login into, correct?Thanks again for your help!
BriteLite
Yes, Authologic comes with an "edit my account" view, but by default would only have the fields available in the User model. You'd need to add the Person fields to the User controller and views to have access to the name. @user.person.name