For some reason my login controller refuses to access a method i have
defined for another class. This is remedial stuff but my searches
haven’t cleared up the issue. It is creating the model but can’t access
the method. The method is NOT protected or private. Any thoughts? The
error:
undefined method `try_to_login’ for #Person:0x37ed3f0
LOGIN CONTROLLER:
class LoginController < ApplicationController
def login
#if a regular page load
if request.get?
#destroy session info and create new person object
session[:person_id] = nil
@person = Person.new
else
#create a new user object and fill it with entered form data
@person = Person.new(params[:person])
#take user object and 'try to log in' (see person model)
logged_in_person = @person.try_to_login
#if log in is successful
if logged_in_person
#set session id to user id and send home
session[:id] = logged_in_person.id
redirect_to :controller => 'room',
:action => 'list'
#otherwise complain
else
flash[:notice] = "Invalid email or password"
end
end
end
PERSON MODEL:
class Person < ActiveRecord::Base
####################################
#LOGIN METHODS (see login controller)
def self.login(name, password)
#hash plaintext password entry
hashed_password = hash_password(password || "")
#return first user record matching entered name and converted
password
find( :first,
:conditions => [“name = ? and hashed_password = ?”,
name, hashed_password])
end
def self.try_to_login
Person.login(self.name, self.password)
end