Introduce Booths to OSEM
This commit is contained in:
parent
4d895ae3bc
commit
66ac45efc8
15 changed files with 268 additions and 1 deletions
83
app/controllers/booths_controller.rb
Normal file
83
app/controllers/booths_controller.rb
Normal file
|
|
@ -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
|
||||||
16
app/models/booth.rb
Normal file
16
app/models/booth.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
class Booth < ActiveRecord::Base
|
||||||
|
belongs_to :conference
|
||||||
|
has_many :booth_requests
|
||||||
|
has_many :users, through: :booth_requests
|
||||||
|
|
||||||
|
validate :title,
|
||||||
|
uniqueness: { case_sensitive: fasle},
|
||||||
|
presence: true
|
||||||
|
|
||||||
|
validates :description,
|
||||||
|
:reasoning,
|
||||||
|
:state,
|
||||||
|
:logo_link
|
||||||
|
:conference_id,
|
||||||
|
presence: true
|
||||||
|
end
|
||||||
10
app/models/booth_request.rb
Normal file
10
app/models/booth_request.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
class BoothRequest < ActiveRecord::Base
|
||||||
|
belongs_to :booth
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
validates :booth,
|
||||||
|
:user,
|
||||||
|
:role,
|
||||||
|
presence: true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -24,6 +24,7 @@ class Conference < ActiveRecord::Base
|
||||||
has_many :supporters, through: :ticket_purchases, source: :user
|
has_many :supporters, through: :ticket_purchases, source: :user
|
||||||
has_many :tickets, dependent: :destroy
|
has_many :tickets, dependent: :destroy
|
||||||
has_many :resources, dependent: :destroy
|
has_many :resources, dependent: :destroy
|
||||||
|
has_many :booths, dependent: :destroy
|
||||||
|
|
||||||
has_many :lodgings, dependent: :destroy
|
has_many :lodgings, dependent: :destroy
|
||||||
has_many :registrations, dependent: :destroy
|
has_many :registrations, dependent: :destroy
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ class User < ActiveRecord::Base
|
||||||
has_many :votes, dependent: :destroy
|
has_many :votes, dependent: :destroy
|
||||||
has_many :voted_events, through: :votes, source: :events
|
has_many :voted_events, through: :votes, source: :events
|
||||||
has_many :subscriptions, dependent: :destroy
|
has_many :subscriptions, dependent: :destroy
|
||||||
|
has_many :booth_requests
|
||||||
|
has_many :booths, through: :users_booths
|
||||||
accepts_nested_attributes_for :roles
|
accepts_nested_attributes_for :roles
|
||||||
|
|
||||||
scope :admin, -> { where(is_admin: true) }
|
scope :admin, -> { where(is_admin: true) }
|
||||||
|
|
|
||||||
28
app/views/booths/_form.html.haml
Normal file
28
app/views/booths/_form.html.haml
Normal file
|
|
@ -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'
|
||||||
7
app/views/booths/edit.html.haml
Normal file
7
app/views/booths/edit.html.haml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
%h1 Editing booth
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
= link_to 'Show', @booth
|
||||||
|
\|
|
||||||
|
= link_to 'Back', booths_path
|
||||||
29
app/views/booths/index.html.haml
Normal file
29
app/views/booths/index.html.haml
Normal file
|
|
@ -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
|
||||||
5
app/views/booths/new.html.haml
Normal file
5
app/views/booths/new.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
%h1 New booth
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
= link_to 'Back', booths_path
|
||||||
24
app/views/booths/show.html.haml
Normal file
24
app/views/booths/show.html.haml
Normal file
|
|
@ -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
|
||||||
14
db/migrate/20170516190048_create_booths.rb
Normal file
14
db/migrate/20170516190048_create_booths.rb
Normal file
|
|
@ -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
|
||||||
11
db/migrate/20170530112510_create_booth_requests.rb
Normal file
11
db/migrate/20170530112510_create_booth_requests.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class CreateBoothRequests < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :booth_requests do |t|
|
||||||
|
t.references :booth, index: true, foreign_key: true
|
||||||
|
t.references :user, index: true, foreign_key: true
|
||||||
|
t.string :role
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
23
db/schema.rb
23
db/schema.rb
|
|
@ -11,6 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170531094819) do
|
ActiveRecord::Schema.define(version: 20170531094819) do
|
||||||
|
|
||||||
create_table "ahoy_events", force: :cascade do |t|
|
create_table "ahoy_events", force: :cascade do |t|
|
||||||
|
|
@ -31,6 +32,28 @@ ActiveRecord::Schema.define(version: 20170531094819) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "booth_requests", force: :cascade do |t|
|
||||||
|
t.integer "booth_id"
|
||||||
|
t.integer "user_id"
|
||||||
|
t.string "role"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "booth_requests", ["booth_id"], name: "index_booth_requests_on_booth_id"
|
||||||
|
add_index "booth_requests", ["user_id"], name: "index_booth_requests_on_user_id"
|
||||||
|
|
||||||
|
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|
|
create_table "campaigns", force: :cascade do |t|
|
||||||
t.integer "conference_id"
|
t.integer "conference_id"
|
||||||
t.string "name"
|
t.string "name"
|
||||||
|
|
|
||||||
7
test/factories/booth_requests.rb
Normal file
7
test/factories/booth_requests.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :booth_request do
|
||||||
|
booth nil
|
||||||
|
user nil
|
||||||
|
role "MyString"
|
||||||
|
end
|
||||||
|
end
|
||||||
7
test/models/booth_request_test.rb
Normal file
7
test/models/booth_request_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class BoothRequestTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue