I think that I need to flesh out the Call.report method, or perhaps
break
it down, because it’s not giving the desired output.
The array calls_logins has the condition in which the @call.login_id =>
1, and this seems key to getting correct results. Wheras, c.report is
more of a general report. Hmm, I do want the general report, but would
also want to filter based on @Login.login as well.
I want to put this condition into @call.report so that only matching
data
is gathered. Hmm, seems like login_id won’t really work for that
Any pointers as how to change @call.report?
thufir@arrakis ~/goodfellow-tool $
thufir@arrakis ~/goodfellow-tool $ script/console
Loading development environment.
calls_logins=Call.find(:all, :conditions => {:login_id => 1},:include
=> :login)
=> [#<Call:0xb705e968 @login=#<Login:0xb705e404 @attributes=
{“employee_id”=>“1”, “id”=>“1”, “login”=>“0123”}>, @attributes=
{“id”=>“1”, “comment”=>“start work”, “created_at”=>“2008-02-08
15:12:13”,
“login_id”=>“1”}>, #<Call:0xb705e260 @login=#<Login:0xb705e404
@attributes={“employee_id”=>“1”, “id”=>“1”, “login”=>“0123”}>,
@attributes={“id”=>“2”, “comment”=>“start call”,
“created_at”=>“2008-02-08 15:12:13”, “login_id”=>“1”}>,
#<Call:0xb705dfcc
@login=#<Login:0xb705e404 @attributes={“employee_id”=>“1”, “id”=>“1”,
“login”=>“0123”}>, @attributes={“id”=>“3”, “comment”=>“start break”,
“created_at”=>“2008-02-08 15:12:13”, “login_id”=>“1”}>]calls_logins.each {|event| puts event.login.login + “\t” +
event.created_at.to_s + “\t” +
?> event.comment}
0123 Fri Feb 08 15:12:13 -0800 2008 start work
0123 Fri Feb 08 15:12:13 -0800 2008 start call
0123 Fri Feb 08 15:12:13 -0800 2008 start break
=> [#<Call:0xb705e968 @login=#<Login:0xb705e404 @attributes=
{“employee_id”=>“1”, “id”=>“1”, “login”=>“0123”}>, @attributes=
{“id”=>“1”, “comment”=>“start work”, “created_at”=>“2008-02-08
15:12:13”,
“login_id”=>“1”}>, #<Call:0xb705e260 @login=#<Login:0xb705e404
@attributes={“employee_id”=>“1”, “id”=>“1”, “login”=>“0123”}>,
@attributes={“id”=>“2”, “comment”=>“start call”,
“created_at”=>“2008-02-08 15:12:13”, “login_id”=>“1”}>,
#<Call:0xb705dfcc
@login=#<Login:0xb705e404 @attributes={“employee_id”=>“1”, “id”=>“1”,
“login”=>“0123”}>, @attributes={“id”=>“3”, “comment”=>“start break”,
“created_at”=>“2008-02-08 15:12:13”, “login_id”=>“1”}>]c=Call.find_by_id(1)
=> #<Call:0xb70505ac @attributes={“id”=>“1”, “comment”=>“start work”,
“login_id”=>“1”, “created_at”=>“2008-02-08 15:12:13”}>c.report.each {|event| puts event.login.login + “\t” +
event.created_at.to_s + “\t” + event.comment}
0123 Fri Feb 08 15:12:13 -0800 2008 start work
0123 Fri Feb 08 15:12:13 -0800 2008 start call
0123 Fri Feb 08 15:12:13 -0800 2008 start break
1234 Fri Feb 08 15:12:13 -0800 2008 start work
=> [#<Call:0xb7045e7c @login=#<Login:0xb7045cb0 @attributes=
{“employee_id”=>“1”, “id”=>“1”, “login”=>“0123”}>, @attributes=
{“id”=>“1”, “comment”=>“start work”, “created_at”=>“2008-02-08
15:12:13”,
“login_id”=>“1”}>, #<Call:0xb7045b48 @login=#<Login:0xb7045cb0
@attributes={“employee_id”=>“1”, “id”=>“1”, “login”=>“0123”}>,
@attributes={“id”=>“2”, “comment”=>“start call”,
“created_at”=>“2008-02-08 15:12:13”, “login_id”=>“1”}>,
#<Call:0xb70458b4
@login=#<Login:0xb7045cb0 @attributes={“employee_id”=>“1”, “id”=>“1”,
“login”=>“0123”}>, @attributes={“id”=>“3”, “comment”=>“start break”,
“created_at”=>“2008-02-08 15:12:13”, “login_id”=>“1”}>,
#<Call:0xb7045620
@login=#<Login:0xb7045454 @attributes={“employee_id”=>“1”, “id”=>“2”,
“login”=>“1234”}>, @attributes={“id”=>“4”, “comment”=>“start work”,
“created_at”=>“2008-02-08 15:12:13”, “login_id”=>“2”}>]quit
thufir@arrakis ~/goodfellow-tool $
thufir@arrakis ~/goodfellow-tool $ cat app/models/call.rb
class Call < ActiveRecord::Base
belongs_to :login
def report
Call.find(:all, :include => [:login, :login])
end
end
thufir@arrakis ~/goodfellow-tool $
thanks,
Thufir