For custom queries that require basically a whole custom SQL statement (your find above doesn't exactly abstract much from you) I like to set up a quick little new model that represents the new information. i.e.
class OperatingExpenseReportDatum
attr_accessor :type, :heading, :total
def initialize(row)
# set values from row, like
@total = row["total"].to_f
end
end
and then write a helper method into the model, something like:
class Expense < AR::Base
...
def self.operating_expenses
rows = connection.select_all "SQL STATEMENT HERE"
rows.map { |row| OperatingExpenseReportDatum.new(row) }
end
end
Then your report generation is all nice:
#controller
@expenses = Expense.operating_expenses
view
<% @expenses.each do |expense| %>
<%= expense.type %>: <%= expense.total %>
<% end %>