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

Returns a new instance of RansackableSort.

Parameters:



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

def initialize(app)
  @app = app
end

Instance Method Details

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

Returns <ActiveRecord::Relation, <String>].

Parameters:

  • env (<ActiveRecord::Relation, <String>] * first element is a scope to be sorted * second is a array with user provided sortings)

    nv [<ActiveRecord::Relation, <String>]

    • first element is a scope to be sorted

    • second is a array with user provided sortings

Returns:

  • (<ActiveRecord::Relation, <String>])

    <ActiveRecord::Relation, <String>]



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

def call(env)
  scope, params = env

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

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