On Sat, 09 Feb 2008 19:09:31 +0000, Thufir wrote:
> 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?
Well, I narrowed down the problem, but my lack of ruby knowledge is 
hindering me.
Basically, I want the output of c.report, below, to match either 
report_one or report_two, depending on the value of c.login_id.
If c.login_id is 1, then the output of report_one is desired.
If c.login_id is 2, then the output of report_two is desired.
Of course, this needs to be calculated dynamically.
	def report
                Call.find(:all, :include => [:login, :login], :conditions 
			=> {:login_id => :login.id}).each {|event| puts 
		event.login.login + "\t" + event.created_at.to_s + "\t" + 
			event.comment}
	end 
Something like the above?  I want to pull only matching Login data...
thufir@arrakis ~/goodfellow-tool $ 
thufir@arrakis ~/goodfellow-tool $ script/console
Loading development environment.>> report_one=Call.find(:all, :conditions => {:login_id =>
1},:include
=> :login)
=> [#<Call:0xb701b488 @login=#<Login:0xb701af24
@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:0xb701ad80
@login=#<Login:0xb701af24
@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:0xb701aaec
@login=#<Login:0xb701af24
@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"}>]>> report_one.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:0xb701b488 @login=#<Login:0xb701af24
@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:0xb701ad80
@login=#<Login:0xb701af24
@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:0xb701aaec
@login=#<Login:0xb701af24
@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"}>]>> report_two=Call.find(:all, :conditions => {:login_id => 2},
:include
=> :login)
=> [#<Call:0xb7008680 @login=#<Login:0xb70084b4
@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"}>]>> report_two.each {|event| puts event.login.login + "\t" + 
event.created_at.to_s + "\t" + event.comment}
1234    Fri Feb 08 15:12:13 -0800 2008  start work
=> [#<Call:0xb7008680 @login=#<Login:0xb70084b4
@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"}>]>> c=Call.find_by_id(4)
=> #<Call:0xb6ffe57c @attributes={"id"=>"4",
"comment"=>"start work",
"login_id"=>"2",
"created_at"=>"2008-02-08
15:12:13"}>>> c.report
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:0xb6ffa008 @login=#<Login:0xb6ff9e3c
@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:0xb6ff9cd4
@login=#<Login:0xb6ff9e3c
@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:0xb6ff9a40
@login=#<Login:0xb6ff9e3c
@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"}>]>> 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], :conditions 
=> {:login_id => 1}).each {|event| puts event.login.login + "\t"
+
event.created_at.to_s + "\t" + event.comment}
        end 
end
thufir@arrakis ~/goodfellow-tool $ 
thanks,
Thufir
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---