2014-08-30 19:59:33 +03:00
|
|
|
class WorkshopsController < ApplicationController
|
|
|
|
before_filter :authenticate_user!
|
2014-09-02 18:31:18 +03:00
|
|
|
before_action :assign_workshop, only: [:show, :edit, :update]
|
2014-08-30 19:59:33 +03:00
|
|
|
|
|
|
|
def index
|
|
|
|
@workshops = Workshop.where user: current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@workshop = Workshop.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@workshop = current_user.workshops.build workshop_params
|
|
|
|
|
|
|
|
if @workshop.save
|
2014-09-02 12:31:15 +03:00
|
|
|
after_save_redirection
|
2014-08-30 19:59:33 +03:00
|
|
|
else
|
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @workshop.update workshop_params
|
2014-09-02 12:31:15 +03:00
|
|
|
after_save_redirection
|
2014-08-30 19:59:33 +03:00
|
|
|
else
|
|
|
|
render :edit, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def assign_workshop
|
2014-09-01 12:57:27 +03:00
|
|
|
@workshop = current_user.workshops.find params[:id]
|
2014-08-30 19:59:33 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def workshop_params
|
2014-09-04 00:39:54 +03:00
|
|
|
params.require(:workshop).permit [:title, :subtitle, :length, :language, :abstract, :description, :notes, :track_id, :agreement]
|
2014-08-30 19:59:33 +03:00
|
|
|
end
|
2014-09-02 12:31:15 +03:00
|
|
|
|
|
|
|
def after_save_redirection
|
|
|
|
if current_user.speaker_profile.present?
|
|
|
|
redirect_to @workshop
|
|
|
|
else
|
|
|
|
redirect_to edit_user_registration_path, alert: I18n.t(:please_fill_in_your_speaker_profile)
|
|
|
|
end
|
|
|
|
end
|
2014-08-30 19:59:33 +03:00
|
|
|
end
|