From 99f4483a161f2600d04081e50dec105e51f4c21a Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 18:34:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=EF=BC=88=E6=9C=AA=E5=AE=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 2237a9cfe..46173c499 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -158,7 +158,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 From 3cdda2a60a02ce2c9668ff94b8a6a0f5cb9801d1 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 19:29:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 33 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index f58abc53f..8fa5e0230 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -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 @@ -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