From 3a7b14f4a51c0fdb8b71720f361a0a8ccf080325 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 27 Feb 2014 16:59:04 -0500 Subject: add game types --- app/assets/javascripts/games.js.coffee | 3 ++ app/assets/stylesheets/games.css.scss | 3 ++ app/controllers/games_controller.rb | 74 ++++++++++++++++++++++++++++++++++ app/helpers/games_helper.rb | 2 + app/models/game.rb | 2 + app/models/game_attribute.rb | 3 ++ app/views/games/_form.html.erb | 21 ++++++++++ app/views/games/edit.html.erb | 6 +++ app/views/games/index.html.erb | 27 +++++++++++++ app/views/games/index.json.jbuilder | 4 ++ app/views/games/new.html.erb | 5 +++ app/views/games/show.html.erb | 9 +++++ app/views/games/show.json.jbuilder | 1 + 13 files changed, 160 insertions(+) create mode 100644 app/assets/javascripts/games.js.coffee create mode 100644 app/assets/stylesheets/games.css.scss create mode 100644 app/controllers/games_controller.rb create mode 100644 app/helpers/games_helper.rb create mode 100644 app/models/game.rb create mode 100644 app/models/game_attribute.rb create mode 100644 app/views/games/_form.html.erb create mode 100644 app/views/games/edit.html.erb create mode 100644 app/views/games/index.html.erb create mode 100644 app/views/games/index.json.jbuilder create mode 100644 app/views/games/new.html.erb create mode 100644 app/views/games/show.html.erb create mode 100644 app/views/games/show.json.jbuilder (limited to 'app') 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? %> +
+

<%= pluralize(@game.errors.count, "error") %> prohibited this game from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_area :name %> +
+
+ <%= f.submit %> +
+<% 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 @@ +

Editing game

+ +<%= 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 @@ +

Listing games

+ + + + + + + + + + + + + <% @games.each do |game| %> + + + + + + + <% end %> + +
Name
<%= game.name %><%= link_to 'Show', game %><%= link_to 'Edit', edit_game_path(game) %><%= link_to 'Destroy', game, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= 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 @@ +

New game

+ +<%= 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 @@ +

<%= notice %>

+ +

+ Name: + <%= @game.name %> +

+ +<%= 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 -- cgit v1.2.3