|
|
|
@ -1,15 +1,16 @@
|
|
|
|
|
class ExerciseController < ApplicationController
|
|
|
|
|
layout "base_courses"
|
|
|
|
|
|
|
|
|
|
before_filter :find_exercise_and_course, :only => [:create_exercise_question]
|
|
|
|
|
before_filter :find_course, :only => [:index,:new,:student_exercise_list,:edit]
|
|
|
|
|
before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit]
|
|
|
|
|
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
# remove_invalid_exercise(@course)
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
|
|
|
|
if @is_teacher
|
|
|
|
|
exercises = @course.exercises
|
|
|
|
|
else
|
|
|
|
|
exercises = @course.exercises.where(:exercise_status => 1)
|
|
|
|
|
exercises = @course.exercises.where(:exercise_status => 2)
|
|
|
|
|
end
|
|
|
|
|
@exercises = paginateHelper exercises,20 #分页
|
|
|
|
|
respond_to do |format|
|
|
|
|
@ -229,6 +230,10 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def remove_invalid_exercise
|
|
|
|
|
excercises = @course.exercises
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_exercise_and_course
|
|
|
|
|
@exercise = Exercise.find params[:id]
|
|
|
|
|
@course = Course.find @exercise.course_id
|
|
|
|
|