osem-fcy/app/controllers/booths_controller.rb
Rahul 8c38de6cfd add alias for booth
Booth can be replaced with any alias by replacing it in alias.en.yml. This change is introduced as some events do not use booth but uses other words such as stand.
2019-08-10 01:51:53 +05:30

103 lines
2.8 KiB
Ruby

# frozen_string_literal: true
class BoothsController < ApplicationController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
skip_authorize_resource only: [:withdraw, :confirm, :restart]
include Invitation
def index
@booths = current_user.booths.where(conference_id: @conference.id).uniq
end
def show; end
def new
@url = conference_booths_path(@conference.short_title)
end
def create
@url = conference_booths_path(@conference.short_title)
@booth.submitter = current_user
if @booth.save
booth_responsible_invite
redirect_to conference_booths_path,
notice: "#{(t 'booth').capitalize} successfully created."
else
flash.now[:error] = "Creating #{t 'booth'} failed. #{@booth.errors.full_messages.to_sentence}."
render :new
end
end
def edit
@url = conference_booth_path(@conference.short_title, @booth.id)
end
def update
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.update_attributes(booth_params)
booth_responsible_invite
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully updated!'
else
flash.now[:error] = "Booth could not be updated. #{@booth.errors.full_messages.to_sentence}."
end
end
def destroy; end
def withdraw
authorize! :update, @booth
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.withdraw!
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully withdrawn'
else
flash.now[:error] = "Booth could not be withdrawn. #{@booth.errors.full_messages.to_sentence}."
end
end
def confirm
authorize! :update, @booth
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.confirm!
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully confirmed'
else
flash.now[:error] = "Booth could not be confirmed. #{@booth.errors.full_messages.to_sentence}."
end
end
def restart
authorize! :update, @booth
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.restart!
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully re-submitted'
else
flash.now[:error] = "Booth could not be re-submitted. #{@booth.errors.full_messages.to_sentence}."
end
end
private
def booth_params
params.require(:booth).permit(:title, :description, :reasoning, :state, :picture, :conference_id,
:created_at, :updated_at, :submitter_relationship, :website_url, :invite_responsible,
responsible_ids: [])
end
end