From 7789e2138fc0479846c20bc68d68973636a4a760 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 12 Mar 2019 21:50:00 -0400 Subject: Started game tracker --- app/controllers/admin/games_controller.rb | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 app/controllers/admin/games_controller.rb (limited to 'app/controllers/admin') 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 @@ +class Admin::GamesController < Admin::AdminController + before_action :set_section + + def index + @games = Game.order(created_at: :desc) + end + + def drafts + @games = Game.where(created_at: :desc) + end + + def new + @game = Game.new + end + + def create + @game = Game.new(game_params) + + if @game.save + flash.notice = "Game created successfully!" + + render :edit + else + flash.alert = "Error creating game." + + render :new + end + end + + def edit + @game = Game.find(params[:id]) + end + + def update + @game = Game.find(params[:id]) + + if @game.update_attributes(game_params) + flash.notice = "Game updated successfully!" + else + flash.alert = "Error updating game." + end + + render :edit + end + + private + + def game_params + params.require(:game).permit(:title, :description, :status, :progress, :score) + end + + def set_section + @section = "games" + end + +end -- cgit 1.4.1