Topic: How to define our own methods in a class
I have a class which helps me to register. Now I have added a new screen so that, once the users have registered they can login by giving their user name and password. so I added the code in the controller to check for the valid username/password.
This method is for bringing up the login screen.
@register = Register.login
This method checks for the valid user name /password.
if request.post? @register = Register.authenticate(params[:username], params[:password])
if @register.nil? flash[:notice] = "Invalid login"
redirect_to :action => 'login'
redirect_to :action => 'form'
I have also added the code under module.
class Register < ActiveRecord::Base
def self.authenticate(username, password)
@register = Register.find(:first, :conditions => ['username = ?', username])
if Register.blank? || Digest::SHA256.hexdigest(password + Register.password_salt) != Register.password_hash
When I click on the login link I get this error "undefined method `login' for Register:Class"
Where am i wrong. Please direct me the path.