about summary refs log tree commit diff stats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin/games_controller.rb56
-rw-r--r--app/controllers/games_controller.rb5
2 files changed, 61 insertions, 0 deletions
diff --git a/app/controllers/admin/games_controller.rb b/app/controllers/admin/games_controller.rb new file mode 100644 index 0000000..5bc6de9 --- /dev/null +++ b/app/controllers/admin/games_controller.rb
@@ -0,0 +1,56 @@
1class Admin::GamesController < Admin::AdminController
2 before_action :set_section
3
4 def index
5 @games = Game.order(created_at: :desc)
6 end
7
8 def drafts
9 @games = Game.where(created_at: :desc)
10 end
11
12 def new
13 @game = Game.new
14 end
15
16 def create
17 @game = Game.new(game_params)
18
19 if @game.save
20 flash.notice = "Game created successfully!"
21
22 render :edit
23 else
24 flash.alert = "Error creating game."
25
26 render :new
27 end
28 end
29
30 def edit
31 @game = Game.find(params[:id])
32 end
33
34 def update
35 @game = Game.find(params[:id])
36
37 if @game.update_attributes(game_params)
38 flash.notice = "Game updated successfully!"
39 else
40 flash.alert = "Error updating game."
41 end
42
43 render :edit
44 end
45
46 private
47
48 def game_params
49 params.require(:game).permit(:title, :description, :status, :progress, :score)
50 end
51
52 def set_section
53 @section = "games"
54 end
55
56end
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb new file mode 100644 index 0000000..7d95b2c --- /dev/null +++ b/app/controllers/games_controller.rb
@@ -0,0 +1,5 @@
1class GamesController < ApplicationController
2 def index
3 @games = Game.all
4 end
5end