Please solve my rails problem

Hi,

In this controller i’ve to put the condition for attandance. I’m doing
attandance application. In this when the user login with username and
password in my attandance table their attandance will marked. now i want
to put the condition that in one day only once their data should go in
to attandance table. If they logged in second time in same day the data
should not go into my table. The should check with date and name. How
can i do this. Please help me to get the answer.

Thanks,
Manjula

On Nov 27, 2007, at 11:23 PM, Manjula R. wrote:

In this controller i’ve to put the condition for attandance. I’m doing
attandance application. In this when the user login with username and
password in my attandance table their attandance will marked. now i
want
to put the condition that in one day only once their data should go in
to attandance table. If they logged in second time in same day the
data
should not go into my table. The should check with date and name. How
can i do this. Please help me to get the answer.

What’s happening now? Does it never find the previous login?
Is date a Date or a Time? If the database has it as a datetime then
Date.today isn’t going to match it.

Hi,

Yes it is not finding the previous login. How may times i’m logging in
the data going into my attandance table. I don’t want this. Only once it
should go in a day.

On Nov 28, 2007, at 12:28 AM, Manjula R. wrote:

Yes it is not finding the previous login. How may times i’m logging in
the data going into my attandance table. I don’t want this. Only
once it
should go in a day.

Is your date column a date or a datetime?

My date column is simple date

On Nov 28, 2007, at 12:41 AM, Manjula R. wrote:

My date column is simple date

Now I see it. You are mixing attandance and @attandance, which are not
the same variable.

(By the way, not that it matters here, but it’s attendance, with an e.)

On Nov 28, 2007, at 1:15 AM, Manjula R. wrote:

what is the condition do i have to write there?

You just have to be consistent.

If you do attendance = Find…

then you have to do

if attendance, not if @attendance.

what is the condition do i have to write there?

I’ve done like this. but also it is not doing anything for my table.
Data is entering into the table. What is the problem here

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