Please solve my rails problem

0 views
Skip to first unread message

Manjula Rajendran

unread,
Nov 28, 2007, 12:23:42 AM11/28/07
to rubyonra...@googlegroups.com
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

Attachments:
http://www.ruby-forum.com/attachment/1049/admin_controller.rb

--
Posted via http://www.ruby-forum.com/.

George Bailey

unread,
Nov 28, 2007, 1:12:45 AM11/28/07
to rubyonra...@googlegroups.com

On Nov 27, 2007, at 11:23 PM, Manjula Rajendran 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.

Manjula Rajendran

unread,
Nov 28, 2007, 1:28:41 AM11/28/07
to rubyonra...@googlegroups.com
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.

George Bailey

unread,
Nov 28, 2007, 1:36:55 AM11/28/07
to rubyonra...@googlegroups.com

On Nov 28, 2007, at 12:28 AM, Manjula Rajendran 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?

Manjula Rajendran

unread,
Nov 28, 2007, 1:41:51 AM11/28/07
to rubyonra...@googlegroups.com

My date column is simple date

George Bailey

unread,
Nov 28, 2007, 1:55:38 AM11/28/07
to rubyonra...@googlegroups.com

On Nov 28, 2007, at 12:41 AM, Manjula Rajendran 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.)

Manjula Rajendran

unread,
Nov 28, 2007, 2:15:13 AM11/28/07
to rubyonra...@googlegroups.com
what is the condition do i have to write there?

George Bailey

unread,
Nov 28, 2007, 2:23:31 AM11/28/07
to rubyonra...@googlegroups.com

On Nov 28, 2007, at 1:15 AM, Manjula Rajendran 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.

Manjula Rajendran

unread,
Nov 28, 2007, 5:35:59 AM11/28/07
to rubyonra...@googlegroups.com
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

Attachments:
http://www.ruby-forum.com/attachment/1051/admin_controller.rb

raghukumar

unread,
Nov 28, 2007, 1:46:53 PM11/28/07
to Ruby on Rails: Talk
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
Reply all
Reply to author
Forward
0 new messages