From 6728b3d059877f2042572f0878679ad05dea6d72 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 17:31:29 +0300 Subject: [PATCH] Lecture creation --- app/controllers/lectures_controller.rb | 21 ++++++++++++++++++++- app/models/event.rb | 1 + app/models/user.rb | 3 +++ app/views/lectures/new.html.slim | 2 +- app/views/lectures/show.html.slim | 22 ++++++++++++++++++++-- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index 1a32a6c..af3ade6 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -1,10 +1,19 @@ class LecturesController < ApplicationController + before_filter :authenticate_user! + before_action :assign_lecture, only: [:show] + def new @lecture = Lecture.new end def create - head :created + @lecture = current_user.lectures.build lecture_params + + if @lecture.save + redirect_to @lecture + else + render :new, status: :unprocessable_entity + end end def edit @@ -15,4 +24,14 @@ class LecturesController < ApplicationController def show end + + private + + def assign_lecture + @lecture = Lecture.find params[:id] + end + + def lecture_params + params.require(:lecture).permit [:title, :subtitle, :length, :language, :abstract, :description, :notes, :track_id] + end end diff --git a/app/models/event.rb b/app/models/event.rb index 3cd353d..50312ab 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -3,6 +3,7 @@ class Event < ActiveRecord::Base validates :length, presence: true, numericality: {only_integer: true, greater_than: 0} validates :abstract, presence: true validates :description, presence: true + validates :track, inclusion: { in: (Conference.current.try(:tracks) || []) } belongs_to :track has_one :conference, through: :track diff --git a/app/models/user.rb b/app/models/user.rb index 58df7b8..f7fa261 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,5 +3,8 @@ class User < ActiveRecord::Base # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable + has_one :speaker_profile + has_many :lectures + has_many :workshops end diff --git a/app/views/lectures/new.html.slim b/app/views/lectures/new.html.slim index db3d176..84cebb5 100644 --- a/app/views/lectures/new.html.slim +++ b/app/views/lectures/new.html.slim @@ -1,2 +1,2 @@ -h1 Предложи нова лекция +h1.entry-title Предложи нова лекция = render 'form' diff --git a/app/views/lectures/show.html.slim b/app/views/lectures/show.html.slim index 4ff9a4e..89ab7ef 100644 --- a/app/views/lectures/show.html.slim +++ b/app/views/lectures/show.html.slim @@ -1,2 +1,20 @@ -h1 Lectures#show -p Find me in app/views/lectures/show.html.slim +h1.entry-title Преглед на лекция + +h2.lecture-title + = @lecture.title + span.subtitle = @lecture.subtitle + .entry-meta + | + поток: „#{@lecture.track.name}“, + продължителност: #{@lecture.length} мин. + +section.abstract + h3 Резюме + = simple_format @lecture.abstract + +section.description + h3 Описание + = simple_format @lecture.description + +- if current_user == @lecture.user + = link_to 'Редактирай', edit_lecture_path(@lecture)