Class: Para::Admin::SearchController

Inherits:
Para::ApplicationController show all
Includes:
Helpers::ResourceName
Defined in:
app/controllers/para/admin/search_controller.rb

Instance Method Summary collapse

Methods included from Helpers::ResourceName

#resource_name

Methods inherited from Para::ApplicationController

#admin?

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/para/admin/search_controller.rb', line 6

def index
  # Parse ids that are provided as string into array
  if params[:q] && params[:q][:id_in].is_a?(String)
    params[:q][:id_in] = params[:q][:id_in].split(',')
  end

  model = params[:model_name].constantize
  @results = model.ransack(params[:q]).result
  @results = @results.limit(params[:limit]) if params[:limit]

  case params[:mode]
  when "selectize"
    render json: @results.map { |res|
      { text: resource_name(res), value: res.id }
    }
  else
    render layout: false
  end
end