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