Merge branch 'sw_new_course' of http://repository.trustie.net/xianbo/trustie2 into sw_new_course

This commit is contained in:
cxt 2015-11-17 19:33:27 +08:00
commit 7472d959f3
1 changed files with 27 additions and 8 deletions

View File

@ -1,7 +1,9 @@
class ExerciseController < ApplicationController
layout "base_courses"
before_filter :find_exercise_and_course, :only => [:create_exercise_question]
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list,:edit]
def index
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
if @is_teacher
@ -36,9 +38,19 @@ class ExerciseController < ApplicationController
end
def new
@exercise = Exercise.new
respond_to do |format|
format.html{render :layout => 'base_courses'}
option = {
:exercise_name => "",
:course_id => @course.id,
:exercise_status => 1,
:user_id => User.current.id,
:time => Time.now,
:end_time => Time.now,
:publish_time => Time.now,
:polls_description => ""
}
@exercise = Exercise.create option
if @exercise
redirect_to edit_exercise_url @exercise.id
end
end
@ -71,10 +83,10 @@ class ExerciseController < ApplicationController
end
def update
@exercise.exercise_name = params[:exercise_name]
@exercise.exercise_description = params[:exercise_name]
@exercise.start_at = params[:start_at]
@exercise.end_at = params[:end_at]
@exercise.exercise_name = params[:exercise][:exercise_name]
@exercise.exercise_description = params[:exercise][:exercise_description]
@exercise.time = params[:exercise][:time]
@exercise.end_time = params[:exercise][:end_time]
if @exercise.save
respond_to do |format|
format.js
@ -176,7 +188,7 @@ class ExerciseController < ApplicationController
question.question_number -= 1
question.save
end
if @poll_question && @poll_question.destroy
if @exercise_question && @exercise_question.destroy
respond_to do |format|
format.js
end
@ -218,6 +230,13 @@ class ExerciseController < ApplicationController
end
private
def find_exercise_and_course
@exercise = Exercise.find params[:id]
@course = Course.find @exercise.course_id
rescue Exception => e
render_404
end
def find_course
@course = Course.find params[:course_id]
rescue Exception => e