Class: Might::RansackableSort

Inherits:
Object
  • Object
show all
Defined in:
lib/might/ransackable_sort.rb

Overview

Sort scope

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RansackableSort



5
6
7
# File 'lib/might/ransackable_sort.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ <ActiveRecord::Relation, <String>]



14
15
16
17
18
19
20
21
# File 'lib/might/ransackable_sort.rb', line 14

def call(env)
  scope, params = env

  ransackable_query = scope.ransack
  ransackable_query.sorts = params[:sort]

  app.call([ransackable_query.result, params])
end