3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/angsa/sorting.rb', line 3
def apply_sorting(records, params)
if params[:order] && params[:dir]
sort = columns.find { |column| column[:name].to_s == params[:order] }
if sort
if sort[:source].include?('.')
association, attribute = sort[:source].split('.')
records = records.joins(association.to_sym).order("#{association.pluralize}.#{attribute} #{params[:dir]}")
else
records = records.order("#{sort[:source]} #{params[:dir]}")
end
end
end
records
end
|