From da6b5b81411a9580037595c32e56caf999d18464 Mon Sep 17 00:00:00 2001 From: nasia Date: Wed, 17 May 2017 13:31:27 +0300 Subject: [PATCH] Create MVC for Booths --- app/controllers/booths_controller.rb | 83 ++++++++++++++++++++++ app/models/booth.rb | 2 + app/views/booths/_form.html.haml | 28 ++++++++ app/views/booths/edit.html.haml | 7 ++ app/views/booths/index.html.haml | 29 ++++++++ app/views/booths/new.html.haml | 5 ++ app/views/booths/show.html.haml | 24 +++++++ db/migrate/20170516190048_create_booths.rb | 14 ++++ db/schema.rb | 14 +++- 9 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 app/controllers/booths_controller.rb create mode 100644 app/models/booth.rb create mode 100644 app/views/booths/_form.html.haml create mode 100644 app/views/booths/edit.html.haml create mode 100644 app/views/booths/index.html.haml create mode 100644 app/views/booths/new.html.haml create mode 100644 app/views/booths/show.html.haml create mode 100644 db/migrate/20170516190048_create_booths.rb diff --git a/app/controllers/booths_controller.rb b/app/controllers/booths_controller.rb new file mode 100644 index 00000000..e739eb3a --- /dev/null +++ b/app/controllers/booths_controller.rb @@ -0,0 +1,83 @@ +class BoothsController < ApplicationController + before_action :set_booth, only: [:show, :edit, :update, :destroy] + + # GET /booths + # GET /booths.json + def index + @booths = Booth.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @booths } + end + end + + # GET /booths/1 + # GET /booths/1.json + def show + respond_to do |format| + format.html # show.html.erb + format.json { render json: @booth } + end + end + + # GET /booths/new + def new + @booth = Booth.new + end + + # GET /booths/1/edit + def edit + end + + # POST /booths + # POST /booths.json + def create + @booth = Booth.new(booth_params) + + respond_to do |format| + if @booth.save + format.html { redirect_to @booth, notice: 'Booth was successfully created.' } + format.json { render json: @booth, status: :created } + else + format.html { render action: 'new' } + format.json { render json: @booth.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /booths/1 + # PATCH/PUT /booths/1.json + def update + respond_to do |format| + if @booth.update(booth_params) + format.html { redirect_to @booth, notice: 'Booth was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @booth.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /booths/1 + # DELETE /booths/1.json + def destroy + @booth.destroy + respond_to do |format| + format.html { redirect_to booths_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_booth + @booth = Booth.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def booth_params + params.require(:booth).permit(:title, :conference_id, :description, :state, :reasoning, :logo_link) + end +end diff --git a/app/models/booth.rb b/app/models/booth.rb new file mode 100644 index 00000000..f1b6fa8d --- /dev/null +++ b/app/models/booth.rb @@ -0,0 +1,2 @@ +class Booth < ActiveRecord::Base +end diff --git a/app/views/booths/_form.html.haml b/app/views/booths/_form.html.haml new file mode 100644 index 00000000..4f85e0f1 --- /dev/null +++ b/app/views/booths/_form.html.haml @@ -0,0 +1,28 @@ += form_for @booth do |f| + - if @booth.errors.any? + #error_explanation + %h2= "#{pluralize(@booth.errors.count, "error")} prohibited this booth from being saved:" + %ul + - @booth.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :title + = f.text_field :title + .field + = f.label :conference_id + = f.number_field :conference_id + .field + = f.label :description + = f.text_area :description + .field + = f.label :state + = f.text_field :state + .field + = f.label :reasoning + = f.text_area :reasoning + .field + = f.label :logo_link + = f.text_field :logo_link + .actions + = f.submit 'Save' diff --git a/app/views/booths/edit.html.haml b/app/views/booths/edit.html.haml new file mode 100644 index 00000000..222d6c97 --- /dev/null +++ b/app/views/booths/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing booth + += render 'form' + += link_to 'Show', @booth +\| += link_to 'Back', booths_path diff --git a/app/views/booths/index.html.haml b/app/views/booths/index.html.haml new file mode 100644 index 00000000..2554b986 --- /dev/null +++ b/app/views/booths/index.html.haml @@ -0,0 +1,29 @@ +%h1 Listing booths + +%table + %tr + %th Title + %th Conference + %th Description + %th State + %th Reasoning + %th Logo link + %th + %th + %th + + - @booths.each do |booth| + %tr + %td= booth.title + %td= booth.conference_id + %td= booth.description + %td= booth.state + %td= booth.reasoning + %td= booth.logo_link + %td= link_to 'Show', booth + %td= link_to 'Edit', edit_booth_path(booth) + %td= link_to 'Destroy', booth, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Booth', new_booth_path diff --git a/app/views/booths/new.html.haml b/app/views/booths/new.html.haml new file mode 100644 index 00000000..3a84ba98 --- /dev/null +++ b/app/views/booths/new.html.haml @@ -0,0 +1,5 @@ +%h1 New booth + += render 'form' + += link_to 'Back', booths_path diff --git a/app/views/booths/show.html.haml b/app/views/booths/show.html.haml new file mode 100644 index 00000000..5c076aca --- /dev/null +++ b/app/views/booths/show.html.haml @@ -0,0 +1,24 @@ +%p#notice= notice + +%p + %b Title: + = @booth.title +%p + %b Conference: + = @booth.conference_id +%p + %b Description: + = @booth.description +%p + %b State: + = @booth.state +%p + %b Reasoning: + = @booth.reasoning +%p + %b Logo link: + = @booth.logo_link + += link_to 'Edit', edit_booth_path(@booth) +\| += link_to 'Back', booths_path diff --git a/db/migrate/20170516190048_create_booths.rb b/db/migrate/20170516190048_create_booths.rb new file mode 100644 index 00000000..3b155bc8 --- /dev/null +++ b/db/migrate/20170516190048_create_booths.rb @@ -0,0 +1,14 @@ +class CreateBooths < ActiveRecord::Migration + def change + create_table :booths do |t| + t.string :title + t.text :description + t.text :reasoning + t.string :state + t.string :logo_link + t.integer :conference_id + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ab95b4dc..4bfb9c2d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170302145716) do +ActiveRecord::Schema.define(version: 20170516190048) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -31,6 +31,17 @@ ActiveRecord::Schema.define(version: 20170302145716) do t.datetime "updated_at" end + create_table "booths", force: :cascade do |t| + t.string "title" + t.text "description" + t.text "reasoning" + t.string "state" + t.string "logo_link" + t.integer "conference_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "campaigns", force: :cascade do |t| t.integer "conference_id" t.string "name" @@ -447,6 +458,7 @@ ActiveRecord::Schema.define(version: 20170302145716) do t.integer "quantity", default: 1 t.integer "user_id" t.integer "payment_id" + t.integer "week" end create_table "tickets", force: :cascade do |t|