Class: Right::RansackableFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/right/ransackable_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RansackableFilter

Returns a new instance of RansackableFilter.

Parameters:



6
7
8
# File 'lib/right/ransackable_filter.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

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

Returns <ActiveRecord::Relation, Hash].

Parameters:

  • env (<ActiveRecord::Relation, Hash] * first element is a scope to be filtered * second is a hash with user provided filters)

    nv [<ActiveRecord::Relation, Hash]

    • first element is a scope to be filtered

    • second is a hash with user provided filters

Returns:

  • (<ActiveRecord::Relation, Hash])

    <ActiveRecord::Relation, Hash]



15
16
17
18
19
# File 'lib/right/ransackable_filter.rb', line 15

def call(env)
  scope, params = env
  filtered_scope = scope.ransack(params[:filter]).result
  app.call([filtered_scope, params])
end