95 lines
2.3 KiB
Ruby
95 lines
2.3 KiB
Ruby
class StudentWorkController < ApplicationController
|
|
layout "base_courses"
|
|
before_filter :find_homework, :only => [:new, :index, :create]
|
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy]
|
|
before_filter :member_of_course, :only => [:index, :new, :create, :show]
|
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
|
|
|
def index
|
|
@stundet_works = @homework.student_works.order("final_score desc")
|
|
respond_to do |format|
|
|
format.html
|
|
end
|
|
end
|
|
|
|
def new
|
|
@stundet_work = StudentWork.new
|
|
respond_to do |format|
|
|
format.html
|
|
end
|
|
end
|
|
|
|
def create
|
|
if params[:student_work]
|
|
stundet_work = StudentWork.new
|
|
stundet_work.name = params[:student_work][:name]
|
|
stundet_work.description = params[:student_work][:description]
|
|
stundet_work.project_id = params[:student_work][:project_id]
|
|
stundet_work.homework_common_id = @homework.id
|
|
stundet_work.user_id = User.current.id
|
|
stundet_work.save_attachments(params[:attachments])
|
|
render_attachment_warning_if_needed(stundet_work)
|
|
if stundet_work.save
|
|
respond_to do |format|
|
|
format.html {
|
|
flash[:notice] = l(:notice_successful_create)
|
|
redirect_to student_work_index_url(:homework => @homework.id)
|
|
}
|
|
end
|
|
return
|
|
end
|
|
end
|
|
respond_to do |format|
|
|
format.html {
|
|
flash[:notice] = l(:notice_failed_create)
|
|
redirect_to new_student_work_url(:homework => @homework.id)
|
|
}
|
|
end
|
|
end
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
def update
|
|
|
|
end
|
|
|
|
def show
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
|
|
end
|
|
|
|
private
|
|
#获取作业
|
|
def find_homework
|
|
@homework = HomeworkCommon.find params[:homework]
|
|
@course = @homework.course
|
|
rescue
|
|
render_404
|
|
end
|
|
#获取作品
|
|
def find_work
|
|
@work = StudentWork.find params[:id]
|
|
@course = @work.homework_common.course
|
|
rescue
|
|
render_404
|
|
end
|
|
|
|
#是不是当前课程的成员
|
|
#当前课程成员才可以看到作品列表
|
|
def member_of_course
|
|
render_403 unless User.current.member_of_course? @course
|
|
end
|
|
|
|
#判断是不是当前作品的提交者
|
|
#提交者可以编辑作品
|
|
def author_of_work
|
|
render_403 unless User.current.id == @work.user_id
|
|
end
|
|
end |