diff --git a/README.md b/README.md index a0c2cf5..66e203f 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,11 @@ first play ## Proposed Schema Table - Seat + has_many Seats User - Games + has_many Games players from seats.users + has_one :current_game ## Game Lifecycle @@ -123,3 +124,17 @@ Attributions Source: http://subtlepatterns.com/felt/ Author: http://atle.co/ + +## Extra suits + +> R. Wayne Schmittberger, in his classic game design primer New Rules for +> Classic Games (1992), describes how you can make your own six-suited +> deck. Obtain two standard decks with the same backs. Set one aside, and +> take the Hearts and Diamonds from the second. Draw an arrow through each +> Heart with a permanent black marker to make a suit of Valentines, and +> draw an 'X' through each Diamond to make a Kites suit. Shuffle these two +> new suits together with the deck you set aside, and presto! a six-suited +> Schmittberger deck! (Of course, you can remove either Kites or +> Valentines to create a five-suited deck like the Stardeck.) + +http://www.thegamesjournal.com/articles/GameSystems2.shtml diff --git a/app/assets/javascripts/tables.js.coffee b/app/assets/javascripts/tables.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/tables.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/application.css.sass b/app/assets/stylesheets/application.css.sass index c2da356..fe5a287 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -40,6 +40,7 @@ h1 header font-size: 3vmin + margin-bottom: 10vmin nav padding: 1vmin background: #222 diff --git a/app/assets/stylesheets/tables.css.scss b/app/assets/stylesheets/tables.css.scss new file mode 100644 index 0000000..ea3e587 --- /dev/null +++ b/app/assets/stylesheets/tables.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Tables 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/tables_controller.rb b/app/controllers/tables_controller.rb new file mode 100644 index 0000000..a039d88 --- /dev/null +++ b/app/controllers/tables_controller.rb @@ -0,0 +1,74 @@ +class TablesController < ApplicationController + before_action :set_table, only: [:show, :edit, :update, :destroy] + + # GET /tables + # GET /tables.json + def index + @tables = Table.all + end + + # GET /tables/1 + # GET /tables/1.json + def show + end + + # GET /tables/new + def new + @table = Table.new + end + + # GET /tables/1/edit + def edit + end + + # POST /tables + # POST /tables.json + def create + @table = Table.new(table_params) + + respond_to do |format| + if @table.save + format.html { redirect_to @table, notice: 'Table was successfully created.' } + format.json { render :show, status: :created, location: @table } + else + format.html { render :new } + format.json { render json: @table.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /tables/1 + # PATCH/PUT /tables/1.json + def update + respond_to do |format| + if @table.update(table_params) + format.html { redirect_to @table, notice: 'Table was successfully updated.' } + format.json { render :show, status: :ok, location: @table } + else + format.html { render :edit } + format.json { render json: @table.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /tables/1 + # DELETE /tables/1.json + def destroy + @table.destroy + respond_to do |format| + format.html { redirect_to tables_url, notice: 'Table was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_table + @table = Table.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def table_params + params.require(:table).permit(:title) + end +end diff --git a/app/helpers/tables_helper.rb b/app/helpers/tables_helper.rb new file mode 100644 index 0000000..35826e3 --- /dev/null +++ b/app/helpers/tables_helper.rb @@ -0,0 +1,2 @@ +module TablesHelper +end diff --git a/app/models/table.rb b/app/models/table.rb index 2933c98..17eaab4 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -1,5 +1,6 @@ class Table < ActiveRecord::Base has_many :seats + has_many :users, through: :seats has_many :games has_one :current_game, :class_name => "Game", :primary_key => "current_game_id" end diff --git a/app/policies/table_policy.rb b/app/policies/table_policy.rb new file mode 100644 index 0000000..c7d591f --- /dev/null +++ b/app/policies/table_policy.rb @@ -0,0 +1,25 @@ +class TablePolicy + attr_reader :current_user, :model + + def initialize(current_user, model) + @current_user = current_user || User.new + @table = model + end + + def index? + @current_user.admin? + end + + def show? + @current_user.admin? || @current_user == @user + end + + def update? + @current_user.admin? # TODO: Allow table owner to edit || @table.owner == @current_user + end + + def destroy? + return false if @current_user == @user + @current_user.admin? + end +end diff --git a/app/views/layouts/_navigation_links.html.erb b/app/views/layouts/_navigation_links.html.erb index 1b652b2..0617046 100644 --- a/app/views/layouts/_navigation_links.html.erb +++ b/app/views/layouts/_navigation_links.html.erb @@ -1,7 +1,7 @@