diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index d6a9d3279..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 @@ -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