class Right::RansackableSort

Sort scope

Attributes

app[R]

Public Class Methods

new(app) click to toggle source

@param app [#call]

# File lib/right/ransackable_sort.rb, line 6
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source

@param env [<ActiveRecord::Relation, <String>]

* first element is a scope to be sorted
* second is a array with user provided sortings

@return [<ActiveRecord::Relation, <String>]

# File lib/right/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