Class: GameShelvesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/game_shelves_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

#add_editionObject


47
48
49
# File 'app/controllers/game_shelves_controller.rb', line 47

def add_edition
	add_game(Edition.find_by_id(params[:edition_id]))
end

#add_expansionObject


51
52
53
# File 'app/controllers/game_shelves_controller.rb', line 51

def add_expansion
	add_game(Expansion.find_by_id(params[:expansion_id]))
end

#add_game(game) ⇒ Object


40
41
42
43
44
45
# File 'app/controllers/game_shelves_controller.rb', line 40

def add_game(game)
	game_shelf = GameShelf.find_by_id(params[:id])
	@shelf_item = add_game_to_shelf(game_shelf, game)

	render json: { :status => :success, :shelf_item => @shelf_item }
end

#createObject


70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/game_shelves_controller.rb', line 70

def create
	@game_shelf = GameShelf.new(game_shelf_params.merge(user: current_user, shelf_type: GameShelf.shelf_types[:custom]))

	@game_shelf.save!
	flash[:notice] = "Your new shelf was created!"
	redirect_to [@game_shelf.user, @game_shelf]

	rescue ActiveRecord::RecordInvalid
		render 'new'
end

#destroyObject


81
82
# File 'app/controllers/game_shelves_controller.rb', line 81

def destroy
end

#indexObject


25
26
27
28
# File 'app/controllers/game_shelves_controller.rb', line 25

def index
	game_shelf = GameShelf.find_by(user_id: current_user.id, shelf_type: GameShelf.shelf_types[:backlog])
	redirect_to [current_user, game_shelf]
end

#newObject


66
67
68
# File 'app/controllers/game_shelves_controller.rb', line 66

def new
	@game_shelf = GameShelf.new(user: current_user)
end

#remove_itemObject


55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/game_shelves_controller.rb', line 55

def remove_item
	shelf_item = ShelfItem.find_by_id(params[:item_id])

	@shelf = shelf_item.game_shelf
	@game = shelf_item.item

	shelf_item.destroy

	render json: { :status => :success, :message => :shelf_item_removed }
end

#renameObject


84
85
# File 'app/controllers/game_shelves_controller.rb', line 84

def rename
end

#showObject


30
31
32
33
34
35
36
37
38
# File 'app/controllers/game_shelves_controller.rb', line 30

def show
	@game_shelf = GameShelf.find_by_id(params[:id])
	if params[:platform].to_s != ""
		@shelf_items = ShelfItem.shelf_items_from_shelf_with_platform(@game_shelf.id, params[:platform]).paginate(:page => params[:page]).order('created_at asc')
	else
		@shelf_items = ShelfItem.where(game_shelf_id: @game_shelf.id).paginate(:page => params[:page]).order('created_at asc')
	end
	@game_shelves = current_user.game_shelves -> {order 'shelf_type asc, id asc'}
end