Permalink
Browse files

added draw scaffold

  • Loading branch information...
1 parent 69f3b00 commit 4f0656cb9ccb4cde0778c078fe9b6f5216c067bb kym committed Feb 22, 2012
View
2 .gitignore
@@ -13,3 +13,5 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
+*~
+
View
2 Gemfile
@@ -4,7 +4,7 @@ gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-
+gem 'grape'
gem 'sqlite3'
View
12 Gemfile.lock
@@ -40,6 +40,12 @@ GEM
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ grape (0.1.5)
+ multi_json
+ multi_xml
+ rack
+ rack-jsonp
+ rack-mount
hike (1.2.1)
i18n (0.6.0)
journey (1.0.2)
@@ -54,10 +60,15 @@ GEM
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
+ multi_xml (0.4.1)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
+ rack-jsonp (1.3.0)
+ rack
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
@@ -108,6 +119,7 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
execjs
+ grape
jquery-rails
rails (= 3.2.1)
sass-rails (~> 3.2.3)
View
38 Gemfile~
@@ -1,38 +0,0 @@
-source 'https://rubygems.org'
-
-gem 'rails', '3.2.1'
-
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
-
-gem 'sqlite3'
-
-
-# Gems used only for assets and not required
-# in production environments by default.
-group :assets do
- gem 'sass-rails', '~> 3.2.3'
- gem 'coffee-rails', '~> 3.2.1'
-
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
- # gem 'therubyracer'
-
- gem 'uglifier', '>= 1.0.3'
-end
-
-gem 'jquery-rails'
-
-# To use ActiveModel has_secure_password
-# gem 'bcrypt-ruby', '~> 3.0.0'
-
-# To use Jbuilder templates for JSON
-# gem 'jbuilder'
-
-# Use unicorn as the web server
-# gem 'unicorn'
-
-# Deploy with Capistrano
-# gem 'capistrano'
-
-# To use debugger
-# gem 'ruby-debug19', :require => 'ruby-debug'
View
3 app/assets/javascripts/draws.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://jashkenas.github.com/coffee-script/
View
3 app/assets/stylesheets/draws.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the draws controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
View
83 app/controllers/draws_controller.rb
@@ -0,0 +1,83 @@
+class DrawsController < ApplicationController
+ # GET /draws
+ # GET /draws.json
+ def index
+ @draws = Draw.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @draws }
+ end
+ end
+
+ # GET /draws/1
+ # GET /draws/1.json
+ def show
+ @draw = Draw.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @draw }
+ end
+ end
+
+ # GET /draws/new
+ # GET /draws/new.json
+ def new
+ @draw = Draw.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @draw }
+ end
+ end
+
+ # GET /draws/1/edit
+ def edit
+ @draw = Draw.find(params[:id])
+ end
+
+ # POST /draws
+ # POST /draws.json
+ def create
+ @draw = Draw.new(params[:draw])
+
+ respond_to do |format|
+ if @draw.save
+ format.html { redirect_to @draw, notice: 'Draw was successfully created.' }
+ format.json { render json: @draw, status: :created, location: @draw }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @draw.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /draws/1
+ # PUT /draws/1.json
+ def update
+ @draw = Draw.find(params[:id])
+
+ respond_to do |format|
+ if @draw.update_attributes(params[:draw])
+ format.html { redirect_to @draw, notice: 'Draw was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @draw.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /draws/1
+ # DELETE /draws/1.json
+ def destroy
+ @draw = Draw.find(params[:id])
+ @draw.destroy
+
+ respond_to do |format|
+ format.html { redirect_to draws_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2 app/helpers/draws_helper.rb
@@ -0,0 +1,2 @@
+module DrawsHelper
+end
View
2 app/models/draw.rb
@@ -0,0 +1,2 @@
+class Draw < ActiveRecord::Base
+end
View
37 app/views/draws/_form.html.erb
@@ -0,0 +1,37 @@
+<%= form_for(@draw) do |f| %>
+ <% if @draw.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@draw.errors.count, "error") %> prohibited this draw from being saved:</h2>
+
+ <ul>
+ <% @draw.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :competition_code %><br />
+ <%= f.text_field :competition_code %>
+ </div>
+ <div class="field">
+ <%= f.label :code %><br />
+ <%= f.text_field :code %>
+ </div>
+ <div class="field">
+ <%= f.label :parameters %><br />
+ <%= f.text_field :parameters %>
+ </div>
+ <div class="field">
+ <%= f.label :draw_type %><br />
+ <%= f.text_field :draw_type %>
+ </div>
+ <div class="field">
+ <%= f.label :selection %><br />
+ <%= f.text_area :selection %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/draws/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing draw</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @draw %> |
+<%= link_to 'Back', draws_path %>
View
31 app/views/draws/index.html.erb
@@ -0,0 +1,31 @@
+<h1>Listing draws</h1>
+
+<table>
+ <tr>
+ <th>Competition code</th>
+ <th>Code</th>
+ <th>Parameters</th>
+ <th>Draw type</th>
+ <th>Selection</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @draws.each do |draw| %>
+ <tr>
+ <td><%= draw.competition_code %></td>
+ <td><%= draw.code %></td>
+ <td><%= draw.parameters %></td>
+ <td><%= draw.draw_type %></td>
+ <td><%= draw.selection %></td>
+ <td><%= link_to 'Show', draw %></td>
+ <td><%= link_to 'Edit', edit_draw_path(draw) %></td>
+ <td><%= link_to 'Destroy', draw, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Draw', new_draw_path %>
View
5 app/views/draws/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New draw</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', draws_path %>
View
30 app/views/draws/show.html.erb
@@ -0,0 +1,30 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Competition code:</b>
+ <%= @draw.competition_code %>
+</p>
+
+<p>
+ <b>Code:</b>
+ <%= @draw.code %>
+</p>
+
+<p>
+ <b>Parameters:</b>
+ <%= @draw.parameters %>
+</p>
+
+<p>
+ <b>Draw type:</b>
+ <%= @draw.draw_type %>
+</p>
+
+<p>
+ <b>Selection:</b>
+ <%= @draw.selection %>
+</p>
+
+
+<%= link_to 'Edit', edit_draw_path(@draw) %> |
+<%= link_to 'Back', draws_path %>
View
2 config/routes.rb
@@ -1,4 +1,6 @@
Winnr::Application.routes.draw do
+ resources :draws
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
13 db/migrate/20120222235823_create_draws.rb
@@ -0,0 +1,13 @@
+class CreateDraws < ActiveRecord::Migration
+ def change
+ create_table :draws do |t|
+ t.string :competition_code
+ t.string :code
+ t.string :parameters
+ t.string :draw_type
+ t.text :selection
+
+ t.timestamps
+ end
+ end
+end
View
15 test/fixtures/draws.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ competition_code: MyString
+ code: MyString
+ parameters: MyString
+ draw_type: MyString
+ selection: MyText
+
+two:
+ competition_code: MyString
+ code: MyString
+ parameters: MyString
+ draw_type: MyString
+ selection: MyText
View
49 test/functional/draws_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class DrawsControllerTest < ActionController::TestCase
+ setup do
+ @draw = draws(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:draws)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create draw" do
+ assert_difference('Draw.count') do
+ post :create, draw: @draw.attributes
+ end
+
+ assert_redirected_to draw_path(assigns(:draw))
+ end
+
+ test "should show draw" do
+ get :show, id: @draw
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @draw
+ assert_response :success
+ end
+
+ test "should update draw" do
+ put :update, id: @draw, draw: @draw.attributes
+ assert_redirected_to draw_path(assigns(:draw))
+ end
+
+ test "should destroy draw" do
+ assert_difference('Draw.count', -1) do
+ delete :destroy, id: @draw
+ end
+
+ assert_redirected_to draws_path
+ end
+end
View
7 test/unit/draw_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class DrawTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/draws_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class DrawsHelperTest < ActionView::TestCase
+end

0 comments on commit 4f0656c

Please sign in to comment.