在我的 Rails 应用程序中,我有以下模型
Transaction
belongs_to :account
belongs_to :agent
belongs_to :program
这是我用来获取数据的查询
def self.efficiency_report(starts=nil, ends=nil)
sql = "SELECT p.abbreviation,ag.name,
t.miles, t.date
FROM transactions t
inner join accounts a on t.account_id = a.id
inner join programs p on a.program_id = p.id
inner join agents ag on t.agent_id = ag.id
Group by p.id , ag.id"
result_array(sql)
end
def self.result_array(sql)
conn = ActiveRecord::Base.connection
res = conn.execute(sql)
results = []
res.each{|r|
results << r
}
return results
end
我想先按程序分组,然后按代理名称分组,然后按里程分组,就像这样
Program:AA
Agent:Bob
Miles Date
1234 02/12/2012
5463 03/12/2012
Agent:Ben
Miles Date
234 02/22/2012
344 01/02/2012
Program:BB
Agent:Bob
Miles Date
1234 02/12/2012
5463 03/12/2012
Agent:Ben
Miles Date
234 02/22/2012
344 01/02/2012
为此,我认为我正在做以下事情
%h2 Vendor Efficiency Report
- @transactions.group_by(&:row[0]).sort.each { |data, transaction|
%h2= data.row[0]
- transaction.group_by(&:row[1]).sort.each { |data, transaction|
%table#data_table.display{:cellpadding => "0", :cellspacing => "0"}
%h3{:style => "clear:both;margin-left:10px"}= data.row[1]
%thead
%tr.odd
%td.bold{:style => "width:60px;"} Miles
%td.bold{:style => "width:60px;"} Date
- for t in transaction
%tbody
%tr
%td{:style => "width:60px;"}= row[2]
%td{:style => "width:60px;"}= row[3]
-}
-}
= will_paginate @transactions
但我收到这个错误
错误的参数类型字符串(预期的过程)
有人会告诉我我在这里做错了什么,或者还有其他更好的分组方式吗?
提前致谢