summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-02-27 16:59:04 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-02-27 16:59:04 -0500
commit3a7b14f4a51c0fdb8b71720f361a0a8ccf080325 (patch)
treeb677c4e56d96dfc872ae58d0d0e45d8243750441 /app
parent8e3e88f52c1f2d73acdcb7fdf60326b5f7717068 (diff)
add game types
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/games.js.coffee3
-rw-r--r--app/assets/stylesheets/games.css.scss3
-rw-r--r--app/controllers/games_controller.rb74
-rw-r--r--app/helpers/games_helper.rb2
-rw-r--r--app/models/game.rb2
-rw-r--r--app/models/game_attribute.rb3
-rw-r--r--app/views/games/_form.html.erb21
-rw-r--r--app/views/games/edit.html.erb6
-rw-r--r--app/views/games/index.html.erb27
-rw-r--r--app/views/games/index.json.jbuilder4
-rw-r--r--app/views/games/new.html.erb5
-rw-r--r--app/views/games/show.html.erb9
-rw-r--r--app/views/games/show.json.jbuilder1
13 files changed, 160 insertions, 0 deletions
diff --git a/app/assets/javascripts/games.js.coffee b/app/assets/javascripts/games.js.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/games.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/games.css.scss b/app/assets/stylesheets/games.css.scss
new file mode 100644
index 0000000..db1b7bc
--- /dev/null
+++ b/app/assets/stylesheets/games.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the games controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
new file mode 100644
index 0000000..0a9d8e8
--- /dev/null
+++ b/app/controllers/games_controller.rb
@@ -0,0 +1,74 @@
+class GamesController < ApplicationController
+ before_action :set_game, only: [:show, :edit, :update, :destroy]
+
+ # GET /games
+ # GET /games.json
+ def index
+ @games = Game.all
+ end
+
+ # GET /games/1
+ # GET /games/1.json
+ def show
+ end
+
+ # GET /games/new
+ def new
+ @game = Game.new
+ end
+
+ # GET /games/1/edit
+ def edit
+ end
+
+ # POST /games
+ # POST /games.json
+ def create
+ @game = Game.new(game_params)
+
+ respond_to do |format|
+ if @game.save
+ format.html { redirect_to @game, notice: 'Game was successfully created.' }
+ format.json { render action: 'show', status: :created, location: @game }
+ else
+ format.html { render action: 'new' }
+ format.json { render json: @game.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /games/1
+ # PATCH/PUT /games/1.json
+ def update
+ respond_to do |format|
+ if @game.update(game_params)
+ format.html { redirect_to @game, notice: 'Game was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: 'edit' }
+ format.json { render json: @game.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /games/1
+ # DELETE /games/1.json
+ def destroy
+ @game.destroy
+ respond_to do |format|
+ format.html { redirect_to games_url }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_game
+ @game = Game.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def game_params
+ params.require(:game).permit(:name)
+ end
+end
diff --git a/app/helpers/games_helper.rb b/app/helpers/games_helper.rb
new file mode 100644
index 0000000..2ef8c1f
--- /dev/null
+++ b/app/helpers/games_helper.rb
@@ -0,0 +1,2 @@
+module GamesHelper
+end
diff --git a/app/models/game.rb b/app/models/game.rb
new file mode 100644
index 0000000..a181c26
--- /dev/null
+++ b/app/models/game.rb
@@ -0,0 +1,2 @@
+class Game < ActiveRecord::Base
+end
diff --git a/app/models/game_attribute.rb b/app/models/game_attribute.rb
new file mode 100644
index 0000000..c12723b
--- /dev/null
+++ b/app/models/game_attribute.rb
@@ -0,0 +1,3 @@
+class GameAttribute < ActiveRecord::Base
+ belongs_to :game
+end
diff --git a/app/views/games/_form.html.erb b/app/views/games/_form.html.erb
new file mode 100644
index 0000000..0bbdd1f
--- /dev/null
+++ b/app/views/games/_form.html.erb
@@ -0,0 +1,21 @@
+<%= form_for(@game) do |f| %>
+ <% if @game.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@game.errors.count, "error") %> prohibited this game from being saved:</h2>
+
+ <ul>
+ <% @game.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br>
+ <%= f.text_area :name %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
diff --git a/app/views/games/edit.html.erb b/app/views/games/edit.html.erb
new file mode 100644
index 0000000..d72bd2e
--- /dev/null
+++ b/app/views/games/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing game</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @game %> |
+<%= link_to 'Back', games_path %>
diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb
new file mode 100644
index 0000000..27d47b6
--- /dev/null
+++ b/app/views/games/index.html.erb
@@ -0,0 +1,27 @@
+<h1>Listing games</h1>
+
+<table>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @games.each do |game| %>
+ <tr>
+ <td><%= game.name %></td>
+ <td><%= link_to 'Show', game %></td>
+ <td><%= link_to 'Edit', edit_game_path(game) %></td>
+ <td><%= link_to 'Destroy', game, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
+
+<%= link_to 'New Game', new_game_path %>
diff --git a/app/views/games/index.json.jbuilder b/app/views/games/index.json.jbuilder
new file mode 100644
index 0000000..90f4236
--- /dev/null
+++ b/app/views/games/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array!(@games) do |game|
+ json.extract! game, :id, :name
+ json.url game_url(game, format: :json)
+end
diff --git a/app/views/games/new.html.erb b/app/views/games/new.html.erb
new file mode 100644
index 0000000..ab95f70
--- /dev/null
+++ b/app/views/games/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New game</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', games_path %>
diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb
new file mode 100644
index 0000000..20d374f
--- /dev/null
+++ b/app/views/games/show.html.erb
@@ -0,0 +1,9 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <strong>Name:</strong>
+ <%= @game.name %>
+</p>
+
+<%= link_to 'Edit', edit_game_path(@game) %> |
+<%= link_to 'Back', games_path %>
diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder
new file mode 100644
index 0000000..a4d8d1c
--- /dev/null
+++ b/app/views/games/show.json.jbuilder
@@ -0,0 +1 @@
+json.extract! @game, :id, :name, :created_at, :updated_at