2014-08-10 23:50:44 +03:00
|
|
|
class LecturesController < ApplicationController
|
2014-08-30 17:31:29 +03:00
|
|
|
before_filter :authenticate_user!
|
2014-10-12 15:10:21 +03:00
|
|
|
before_action :assign_lecture, only: [:show, :edit, :update, :confirm]
|
2014-08-30 17:31:29 +03:00
|
|
|
|
2014-08-30 19:45:25 +03:00
|
|
|
def index
|
|
|
|
@lectures = Lecture.where user: current_user
|
|
|
|
end
|
|
|
|
|
2014-08-10 23:50:44 +03:00
|
|
|
def new
|
|
|
|
@lecture = Lecture.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-08-30 17:31:29 +03:00
|
|
|
@lecture = current_user.lectures.build lecture_params
|
|
|
|
|
|
|
|
if @lecture.save
|
2014-09-02 12:31:15 +03:00
|
|
|
after_save_redirection
|
2014-08-30 17:31:29 +03:00
|
|
|
else
|
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
end
|
2014-08-10 23:50:44 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-08-30 17:37:08 +03:00
|
|
|
if @lecture.update lecture_params
|
2014-09-02 12:31:15 +03:00
|
|
|
after_save_redirection
|
2014-08-30 17:37:08 +03:00
|
|
|
else
|
|
|
|
render :edit, status: :unprocessable_entity
|
|
|
|
end
|
2014-08-10 23:50:44 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
2014-08-30 17:31:29 +03:00
|
|
|
|
2014-10-12 15:10:21 +03:00
|
|
|
def confirm
|
|
|
|
@lecture.touch :confirmed_at
|
|
|
|
redirect_to @lecture, notice: I18n.t(:lecture_was_successfully_confirmed)
|
|
|
|
end
|
|
|
|
|
2014-08-30 17:31:29 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
def assign_lecture
|
2014-09-01 12:57:27 +03:00
|
|
|
@lecture = current_user.lectures.find params[:id]
|
2014-08-30 17:31:29 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def lecture_params
|
2014-09-04 00:39:54 +03:00
|
|
|
params.require(:lecture).permit [:title, :subtitle, :length, :language, :abstract, :description, :notes, :track_id, :agreement]
|
2014-08-30 17:31:29 +03:00
|
|
|
end
|
2014-09-02 12:31:15 +03:00
|
|
|
|
|
|
|
def after_save_redirection
|
|
|
|
if current_user.speaker_profile.present?
|
|
|
|
redirect_to @lecture
|
|
|
|
else
|
|
|
|
redirect_to edit_user_registration_path, alert: I18n.t(:please_fill_in_your_speaker_profile)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-10 23:50:44 +03:00
|
|
|
end
|