Class: GamesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#_edition_exists, #after_sign_in_path_for, #deny_access, #expansion_exists, #fill_platforms, #game_exists, #game_maker_only, #has_query, #ignore_referral_spam, #reviewer_only, #work_exists, #xhr_only

Instance Method Details

#indexObject


45
46
47
48
49
50
51
52
# File 'app/controllers/games_controller.rb', line 45

def index
	@search = GamesSearch.new(platform: params[:platform])
	results = @search.all
	results_paginated = results.paginate(:page => params[:page])
	@page_object = PagingObject.new(results_paginated.total_pages, params[:page], results_paginated.per_page, results_paginated.total)
	@user_shelves = GameShelf.user_shelves(current_user.id) if current_user
	@games = GamesIndexViewObject.construct_array_from_chewy_map(results_paginated.map)
end

#searchObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/games_controller.rb', line 10

def search
	@search = GamesSearch.new(query: params[:q], platform: params[:platform], type: params[:type])
	results = @search.search
	results_paginated = results.paginate(:page => params[:page])
	@total = results_paginated.total
	@qty = results_paginated.count
	@user_shelves = GameShelf.user_shelves(current_user.id) if current_user
	respond_to do |format|
		format.html {
			if @qty == 1
				if results_paginated.map.first.expansion_id
					redirect_to edition_expansion_path(results_paginated.map.first.edition_id, results_paginated.map.first.expansion_id)
				else
					redirect_to edition_path(results_paginated.map.first.edition_id)
				end
			end
			@page_object = PagingObject.new(results_paginated.total_pages, params[:page], results_paginated.per_page, results_paginated.total)
			@games = GamesIndexViewObject.construct_array_from_chewy_map(results_paginated.map)
		}
		format.json {
			render :json => { :games => results_paginated.to_a }
		}
	end
end

#search_for_transformationObject


35
36
37
38
39
40
41
42
43
# File 'app/controllers/games_controller.rb', line 35

def search_for_transformation
	@search = GamesSearch.new(query: params[:q], platform: params[:platform], type: 'edition', not_id: params[:id])
	results = @search.search.only(:id)
	@games = results.paginate(:page => params[:page]).load(edition: {scope: Edition.includes(:work)})
	@total = @games.total
	@qty = @games.count
	render :partial => 'shared/transformation_editions', :locals =>
	{:games => @games}
end