def login
session[:user_id] = nil
if request.post?
user = User.authenticate(params[:name], params[:password])
if user
session[:user_id] = user.id
if user.user_type==‘admin’
redirect_to :controller
=>‘admin_information’,:action=>‘emp_list’
elsif(user.user_type==‘user’)
p "-------------finding in db-----------------"
attandance = Attandance.find(:first, :conditions=>['name=?
and date=?’,user.name,Date.today])
if attandance
flash[:notice]=“Already entered”
redirect_to :controller=>‘information’, :action=>‘emp_list’
else
time_in = Time.now
if time_in.hour > 10 and time_in.min > 10
attandance =
Attandance.create(:time_in=>Time.now,:name=>user.name,:present=>‘late’,:date=>Date.today,:information_id=>@information_id)
else
attandance =
Attandance.create(:time_in=>Time.now,:name=>user.name,:present=>‘Yes’,:date=>Date.today,:information_id=>@information_id)
end
#if @attandance.name==user.name and
@attandance.present==‘yes’
#attandance = Attandance.find(:first, :conditions=>['name=?
and date=?’,user.name, Date.today])
# if @attandance
#flash[:notice]=“Already entered”
#else
p “------#{@information_id}-----------”
#attandance =
Attandance.create(:time_in=>Time.now,:name=>user.name,
:present=>‘Yes’,:date=>Date.today,:information_id=>@information_id)
#@people = Person.find_recent
# @attandance = Attandance.time_in
#end
flash[:notice]=“Your attandance is marked”
redirect_to :controller =>‘information’,:action=>‘emp_list’
end
end
#redirect_to :controller=>“admin_information”, :action =>
“emp_list”
else
p"---------no msg-------------"
flash[:notice] = “Invalid user/password combination”
end
end
end
changed
if @attandance
To
if attandance.
Suggestion:
Better to move logic of late coming into corresponding model. (write
UT’s)
Note:
If you are not sure when to use @attendance and attendance, please
read Ruby book OR Ask some one.
Thanks,
Regards,
Raghu Kumar K