最佳答案
I'm using rails ransack ( https://github.com/ernie/ransack ) to allow the users to filter and sort some records. I get the filtered and sorted records using traditional methods.
@invoices = Invoice.search(params[:q]).result
Now I would like to get some summary information so I have
@invoices = Invoice.search(params[:q]).result
@summary = @invoices.select("sum(balance) as balance_total").first
Except when the user specifies a field to sort. I get the SQL error:
Column "project_name" is invalid in the ORDER BY clause because
it is not contained in either an aggregate function or the GROUP BY clause
Can I remove the sort from the scope? How?
Thanks