Class: RecommendationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/recommendations_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/recommendations_controller.rb', line 4

def index
  if params[:language].present?
    @language = Project.language(params[:language].downcase).first.try(:language)
    raise ActiveRecord::RecordNotFound if @language.nil?
    scope = current_user.recommended_projects.language(@language)
  else
    scope = current_user.recommended_projects
  end

  if params[:license].present?
    @license = Spdx.find(params[:license]) if params[:license].present?
    raise ActiveRecord::RecordNotFound if @license.nil?
    scope = scope.license(@license.id)
  end

  if params[:platform].present?
    @platform = Project.platform(params[:platform].downcase).first.try(:platform)
    raise ActiveRecord::RecordNotFound if @platform.nil?
    scope = scope.platform(@platform)
  end

  @languages = current_user.recommended_projects.pluck('language').compact.uniq
  @licenses = current_user.recommended_projects.pluck('normalized_licenses').compact.flatten.uniq
  @platforms = current_user.recommended_projects.pluck('platform').compact.uniq
  @projects = scope.paginate(page: page_number, per_page: 20)
end