Lecture creation

This commit is contained in:
Petko Bordjukov 2014-08-30 17:31:29 +03:00
parent 0190ee077f
commit 6728b3d059
5 changed files with 45 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,2 +1,2 @@
h1 Предложи нова лекция
h1.entry-title Предложи нова лекция
= render 'form'

View File

@ -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)