|
|
|
class CourseVideosController < ApplicationController
|
|
|
|
before_action :require_login
|
|
|
|
before_action :validate_params
|
|
|
|
before_action :find_course, only: [:create]
|
|
|
|
before_action :find_video, only: [:update]
|
|
|
|
before_action :teacher_allowed
|
|
|
|
|
|
|
|
def create
|
|
|
|
title = params[:name].strip
|
|
|
|
link = params[:link].strip
|
|
|
|
course_second_category_id = params[:category_id] || 0
|
|
|
|
@course.course_videos.create!(title: title, link: link, is_link: 1, user_id: current_user.id, course_second_category_id: course_second_category_id)
|
|
|
|
render_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
title = params[:name].strip
|
|
|
|
link = params[:link].strip
|
|
|
|
@video.update!(title: title, link: link)
|
|
|
|
render_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_params
|
|
|
|
tip_exception("视频名称不能为空") if params[:name].blank?
|
|
|
|
tip_exception("链接地址不能为空") if params[:link].blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_video
|
|
|
|
@video = CourseVideo.find params[:id]
|
|
|
|
@course = @video.course
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|