ruby on rails - Ransack won't sort counted column? -


i have problem sorting.

ransack works fine when sorting id , mac columns, won't work on frequency column. in logs nothing appeared when clicked on frequency.

model:

scope :with_frequency, -> { select('devices.*,tr.times frequency'). joins('join (select device_id,count(device_id) times timed_requests tr group device_id) tr on tr.device_id = devices.id')} 

controller:

def index @search = device.with_frequency.search(params[:q]) @search.sorts = 'frequency desc' if @search.sorts.empty? @devices = @search.result.paginate(page: params[:page], per_page: 20) end 

view:

%th= sort_link @search, :id, "id" %th= sort_link @search, :mac, "mac-addresse" %th= sort_link @search, :frequency, "frequency" 

logs (first click on frequency id):

parameters: {"page"=>"1", "q"=>{"s"=>"frequency desc"}} device load (39.8ms)  select devices.*,tr.times frequency "devices" join (select     device_id,count(device_id) times timed_requests tr group device_id) tr on        tr.device_id = devices.id limit 20 offset 0  parameters: {"page"=>"1", "q"=>{"s"=>"id asc"}} device load (61.3ms)  select devices.*,tr.times frequency "devices" join (select device_id,count(device_id) times timed_requests tr group device_id) tr on tr.device_id = devices.id order "devices"."id" asc limit 20 offset 0 

thanks help.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -