Refactor admin/call_for_booth controller
This commit is contained in:
parent
9103f511a7
commit
318c0d15a4
17 changed files with 182 additions and 18 deletions
21
app/controllers/admin/booths_controller.rb
Normal file
21
app/controllers/admin/booths_controller.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
module Admin
|
||||||
|
class Admin::BoothsController < Admin::BaseController
|
||||||
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
|
load_and_authorize_resource :booth, through: :conference
|
||||||
|
|
||||||
|
def index
|
||||||
|
@booths = @conference.booths
|
||||||
|
end
|
||||||
|
|
||||||
|
def show; end
|
||||||
|
|
||||||
|
def new; end
|
||||||
|
|
||||||
|
def create; end
|
||||||
|
|
||||||
|
def update; end
|
||||||
|
|
||||||
|
def destroy; end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
55
app/controllers/admin/call_for_booths_controller.rb
Normal file
55
app/controllers/admin/call_for_booths_controller.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
module Admin
|
||||||
|
class CallForBoothsController < Admin::BaseController
|
||||||
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
|
load_and_authorize_resource through: :conference, singleton: true
|
||||||
|
|
||||||
|
def show; end
|
||||||
|
|
||||||
|
|
||||||
|
def new
|
||||||
|
@call_for_booth = CallForBooth.new(conference: @conference)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit; end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@call_for_booth = @conference.call_for_booth.build(call_for_booth_params)
|
||||||
|
|
||||||
|
if @call_for_booth.save
|
||||||
|
redirect_to admin_conference_call_for_booth_path,
|
||||||
|
notice: "Call for booths successfully created."
|
||||||
|
else
|
||||||
|
flash[:error] = "Creating the call for booths failed. #{@call_for_booth.errors.full_messages.join('. ')}."
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@call_for_booth = @conference.call_for_booth
|
||||||
|
@call_for_booth.assign_attributes(call_for_booth_params)
|
||||||
|
|
||||||
|
if @call_for_booth.update_attributes(call_for_booth_params)
|
||||||
|
redirect_to admin_conference_call_for_booth_path(@conference.short_title),
|
||||||
|
notice: 'Call for booths successfully updated.'
|
||||||
|
else
|
||||||
|
flash.now[:error] = "Updating call for booths failed. #{@call_for_booth.errors.to_a.join('. ')}."
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @call_for_booth.destroy
|
||||||
|
redirect_to admin_conference_call_for_booth_path, notice: 'Call for Booths successfully deleted.'
|
||||||
|
else
|
||||||
|
redirect_to admin_conference_call_for_booth_path, error: 'An error prohibited this Call for Booths from being destroyed: '\
|
||||||
|
"#{@call_for_booth.errors.full_messages.join('. ')}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def call_for_booth_params
|
||||||
|
params.require(:call_for_booth).permit(:start_date, :end_date, :booth_limit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -2,22 +2,18 @@ class BoothsController < ApplicationController
|
||||||
before_action :set_booth, only: [:show, :edit, :update, :destroy]
|
before_action :set_booth, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
# GET /booths
|
# GET /booths
|
||||||
# GET /booths.json
|
|
||||||
def index
|
def index
|
||||||
@booths = Booth.all
|
@booths = Booth.all
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render json: @booths }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /booths/1
|
# GET /booths/1
|
||||||
# GET /booths/1.json
|
|
||||||
def show
|
def show
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # show.html.erb
|
format.html # show.html.erb
|
||||||
format.json { render json: @booth }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -31,42 +27,34 @@ class BoothsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /booths
|
# POST /booths
|
||||||
# POST /booths.json
|
|
||||||
def create
|
def create
|
||||||
@booth = Booth.new(booth_params)
|
@booth = Booth.new(booth_params)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @booth.save
|
if @booth.save
|
||||||
format.html { redirect_to @booth, notice: 'Booth was successfully created.' }
|
format.html { redirect_to @booth, notice: 'Booth was successfully created.' }
|
||||||
format.json { render json: @booth, status: :created }
|
|
||||||
else
|
else
|
||||||
format.html { render action: 'new' }
|
format.html { render action: 'new' }
|
||||||
format.json { render json: @booth.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PATCH/PUT /booths/1
|
# PATCH/PUT /booths/1
|
||||||
# PATCH/PUT /booths/1.json
|
|
||||||
def update
|
def update
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @booth.update(booth_params)
|
if @booth.update(booth_params)
|
||||||
format.html { redirect_to @booth, notice: 'Booth was successfully updated.' }
|
format.html { redirect_to @booth, notice: 'Booth was successfully updated.' }
|
||||||
format.json { head :no_content }
|
|
||||||
else
|
else
|
||||||
format.html { render action: 'edit' }
|
format.html { render action: 'edit' }
|
||||||
format.json { render json: @booth.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /booths/1
|
# DELETE /booths/1
|
||||||
# DELETE /booths/1.json
|
|
||||||
def destroy
|
def destroy
|
||||||
@booth.destroy
|
@booth.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to booths_url }
|
format.html { redirect_to booths_url }
|
||||||
format.json { head :no_content }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ class Booth < ActiveRecord::Base
|
||||||
has_many :users, through: :booth_requests
|
has_many :users, through: :booth_requests
|
||||||
|
|
||||||
validates :title,
|
validates :title,
|
||||||
uniqueness: { case_sensitive: fasle},
|
uniqueness: { case_sensitive: false },
|
||||||
presence: true
|
presence: true
|
||||||
|
|
||||||
validates :description,
|
validates :description,
|
||||||
:reasoning,
|
:reasoning,
|
||||||
:state,
|
:state,
|
||||||
:logo_link
|
:logo_link,
|
||||||
:conference_id,
|
:conference_id,
|
||||||
presence: true
|
presence: true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
class CallForBooth < ActiveRecord::Base
|
class CallForBooth < ActiveRecord::Base
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
|
|
||||||
has_one :conference
|
|
||||||
|
|
||||||
validates :start_date, :end_date, :booth_limit, presence: true
|
validates :start_date, :end_date, :booth_limit, presence: true
|
||||||
validate :before_end_of_conference
|
validate :before_end_of_conference
|
||||||
validate :start_date_before_end_date
|
validate :start_date_before_end_date
|
||||||
|
|
|
||||||
28
app/views/admin/booths/_form.html.haml
Normal file
28
app/views/admin/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/admin/booths/edit.html.haml
Normal file
7
app/views/admin/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/admin/booths/index.html.haml
Normal file
29
app/views/admin/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_admin_conference_booth_path
|
||||||
5
app/views/admin/booths/new.html.haml
Normal file
5
app/views/admin/booths/new.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
%h1 New booth
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
= link_to 'Back', booths_path
|
||||||
24
app/views/admin/booths/show.html.haml
Normal file
24
app/views/admin/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
|
||||||
|
|
@ -4,6 +4,7 @@ class CreateCallForBooths < ActiveRecord::Migration
|
||||||
t.date :start_date
|
t.date :start_date
|
||||||
t.date :end_date
|
t.date :end_date
|
||||||
t.integer :booth_limit
|
t.integer :booth_limit
|
||||||
|
t.references :conference
|
||||||
|
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
12
db/schema.rb
12
db/schema.rb
|
|
@ -11,8 +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: 20170606182954) do
|
||||||
ActiveRecord::Schema.define(version: 20170531094819) do
|
|
||||||
|
|
||||||
create_table "ahoy_events", force: :cascade do |t|
|
create_table "ahoy_events", force: :cascade do |t|
|
||||||
t.uuid "visit_id", limit: 16
|
t.uuid "visit_id", limit: 16
|
||||||
|
|
@ -54,6 +53,15 @@ ActiveRecord::Schema.define(version: 20170531094819) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "call_for_booths", force: :cascade do |t|
|
||||||
|
t.date "start_date"
|
||||||
|
t.date "end_date"
|
||||||
|
t.integer "booth_limit"
|
||||||
|
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"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue