diff options
| author | mo khan <mo@mokhan.ca> | 2015-02-02 21:34:28 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-02-02 21:34:28 -0700 |
| commit | 543b37a327d8ad70cd2c46666759f5fae06f6c32 (patch) | |
| tree | 6c24e4dea87d79cc7e7bb93720d2edd0999adac0 | |
| parent | 013bcebf8a96b9047317eed674a17c7bc375093f (diff) | |
create scaffold for events.
| -rw-r--r-- | app/assets/javascripts/events.coffee | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/events.scss | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/scaffolds.scss | 69 | ||||
| -rw-r--r-- | app/controllers/events_controller.rb | 74 | ||||
| -rw-r--r-- | app/helpers/events_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/event.rb | 2 | ||||
| -rw-r--r-- | app/views/events/_form.html.erb | 25 | ||||
| -rw-r--r-- | app/views/events/edit.html.erb | 6 | ||||
| -rw-r--r-- | app/views/events/index.html.erb | 29 | ||||
| -rw-r--r-- | app/views/events/index.json.jbuilder | 4 | ||||
| -rw-r--r-- | app/views/events/new.html.erb | 5 | ||||
| -rw-r--r-- | app/views/events/show.html.erb | 14 | ||||
| -rw-r--r-- | app/views/events/show.json.jbuilder | 1 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20150203043317_create_events.rb | 11 | ||||
| -rw-r--r-- | db/schema.rb | 27 |
16 files changed, 277 insertions, 0 deletions
diff --git a/app/assets/javascripts/events.coffee b/app/assets/javascripts/events.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/events.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/events.scss b/app/assets/stylesheets/events.scss new file mode 100644 index 0000000..e975d96 --- /dev/null +++ b/app/assets/stylesheets/events.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Events controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,69 @@ +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; + } +} diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb new file mode 100644 index 0000000..63ca73d --- /dev/null +++ b/app/controllers/events_controller.rb @@ -0,0 +1,74 @@ +class EventsController < ApplicationController + before_action :set_event, only: [:show, :edit, :update, :destroy] + + # GET /events + # GET /events.json + def index + @events = Event.all + end + + # GET /events/1 + # GET /events/1.json + def show + end + + # GET /events/new + def new + @event = Event.new + end + + # GET /events/1/edit + def edit + end + + # POST /events + # POST /events.json + def create + @event = Event.new(event_params) + + respond_to do |format| + if @event.save + format.html { redirect_to @event, notice: 'Event was successfully created.' } + format.json { render :show, status: :created, location: @event } + else + format.html { render :new } + format.json { render json: @event.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /events/1 + # PATCH/PUT /events/1.json + def update + respond_to do |format| + if @event.update(event_params) + format.html { redirect_to @event, notice: 'Event was successfully updated.' } + format.json { render :show, status: :ok, location: @event } + else + format.html { render :edit } + format.json { render json: @event.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /events/1 + # DELETE /events/1.json + def destroy + @event.destroy + respond_to do |format| + format.html { redirect_to events_url, notice: 'Event was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_event + @event = Event.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def event_params + params.require(:event).permit(:name, :data) + end +end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb new file mode 100644 index 0000000..8a9a878 --- /dev/null +++ b/app/helpers/events_helper.rb @@ -0,0 +1,2 @@ +module EventsHelper +end diff --git a/app/models/event.rb b/app/models/event.rb new file mode 100644 index 0000000..3a829fd --- /dev/null +++ b/app/models/event.rb @@ -0,0 +1,2 @@ +class Event < ActiveRecord::Base +end diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb new file mode 100644 index 0000000..a803510 --- /dev/null +++ b/app/views/events/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@event) do |f| %> + <% if @event.errors.any? %> + <div id="error_explanation"> + <h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2> + + <ul> + <% @event.errors.full_messages.each do |message| %> + <li><%= message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div class="field"> + <%= f.label :name %><br> + <%= f.text_field :name %> + </div> + <div class="field"> + <%= f.label :data %><br> + <%= f.text_field :data %> + </div> + <div class="actions"> + <%= f.submit %> + </div> +<% end %> diff --git a/app/views/events/edit.html.erb b/app/views/events/edit.html.erb new file mode 100644 index 0000000..b61ac84 --- /dev/null +++ b/app/views/events/edit.html.erb @@ -0,0 +1,6 @@ +<h1>Editing Event</h1> + +<%= render 'form' %> + +<%= link_to 'Show', @event %> | +<%= link_to 'Back', events_path %> diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb new file mode 100644 index 0000000..f4d2bba --- /dev/null +++ b/app/views/events/index.html.erb @@ -0,0 +1,29 @@ +<p id="notice"><%= notice %></p> + +<h1>Listing Events</h1> + +<table> + <thead> + <tr> + <th>Name</th> + <th>Data</th> + <th colspan="3"></th> + </tr> + </thead> + + <tbody> + <% @events.each do |event| %> + <tr> + <td><%= event.name %></td> + <td><%= event.data %></td> + <td><%= link_to 'Show', event %></td> + <td><%= link_to 'Edit', edit_event_path(event) %></td> + <td><%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %></td> + </tr> + <% end %> + </tbody> +</table> + +<br> + +<%= link_to 'New Event', new_event_path %> diff --git a/app/views/events/index.json.jbuilder b/app/views/events/index.json.jbuilder new file mode 100644 index 0000000..bf0491d --- /dev/null +++ b/app/views/events/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@events) do |event| + json.extract! event, :id, :name, :data + json.url event_url(event, format: :json) +end diff --git a/app/views/events/new.html.erb b/app/views/events/new.html.erb new file mode 100644 index 0000000..86707c1 --- /dev/null +++ b/app/views/events/new.html.erb @@ -0,0 +1,5 @@ +<h1>New Event</h1> + +<%= render 'form' %> + +<%= link_to 'Back', events_path %> diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb new file mode 100644 index 0000000..a89623e --- /dev/null +++ b/app/views/events/show.html.erb @@ -0,0 +1,14 @@ +<p id="notice"><%= notice %></p> + +<p> + <strong>Name:</strong> + <%= @event.name %> +</p> + +<p> + <strong>Data:</strong> + <%= @event.data %> +</p> + +<%= link_to 'Edit', edit_event_path(@event) %> | +<%= link_to 'Back', events_path %> diff --git a/app/views/events/show.json.jbuilder b/app/views/events/show.json.jbuilder new file mode 100644 index 0000000..a196f20 --- /dev/null +++ b/app/views/events/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @event, :id, :name, :data, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 3f66539..4aca907 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + resources :events + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20150203043317_create_events.rb b/db/migrate/20150203043317_create_events.rb new file mode 100644 index 0000000..744bc55 --- /dev/null +++ b/db/migrate/20150203043317_create_events.rb @@ -0,0 +1,11 @@ +class CreateEvents < ActiveRecord::Migration + def change + enable_extension 'uuid-ossp' unless extension_enabled?('uuid-ossp') + create_table :events, id: :uuid, default: 'uuid_generate_v4()' do |t| + t.string :name + t.json :data + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..1ca961b --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,27 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20150203043317) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + enable_extension "uuid-ossp" + + create_table "events", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t| + t.string "name" + t.json "data" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end |
