diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-12 21:50:00 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-12 21:50:00 -0400 |
commit | 7789e2138fc0479846c20bc68d68973636a4a760 (patch) | |
tree | ef14af7a0a6e0de8f086a2b2db877840eb48904c /app/controllers/admin | |
parent | 7a2d945f581c8ce9e322883ec597366143fe10cb (diff) | |
download | thoughts-7789e2138fc0479846c20bc68d68973636a4a760.tar.gz thoughts-7789e2138fc0479846c20bc68d68973636a4a760.tar.bz2 thoughts-7789e2138fc0479846c20bc68d68973636a4a760.zip |
Started game tracker
Diffstat (limited to 'app/controllers/admin')
-rw-r--r-- | app/controllers/admin/games_controller.rb | 56 |
1 files changed, 56 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 @@ | |||
1 | class 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 | |||
56 | end | ||