From 02db1b7e142c957786085bdf7952d10d649cce2e Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 21:13:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E5=87=86=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 6 +++++- app/views/exercise/_new_MC.html.erb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 4d2e266b5..8ca8ca31f 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -125,7 +125,7 @@ class ExerciseController < ApplicationController for i in 1..params[:question_answer].count answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] question_option = { - :answer_position => i, + :exercise_choice_id => i, :answer_text => answer } @exercise_questions.exercise_answers.new question_option @@ -139,6 +139,10 @@ class ExerciseController < ApplicationController @exercise_questions.question_number = params[:quest_num].to_i + 1 end if @exercise_questions.save + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + standart_answer.exercise_choice_id = params[:exercise_choice] + standart_answer.save respond_to do |format| format.js end diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index de7e9ba31..1b82d35ce 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -43,7 +43,7 @@
  • - +
  • From 282c7f5bd2fe7c7779164af93a201f762bc51d5c Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 10:46:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 18 +++++++++++------- ...151118014720_add_show_result_to_exercise.rb | 5 +++++ ..._add_question_score_to_exercise_question.rb | 5 +++++ db/schema.rb | 4 +++- 4 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20151118014720_add_show_result_to_exercise.rb create mode 100644 db/migrate/20151118015638_add_question_score_to_exercise_question.rb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 8ca8ca31f..c892b6583 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,8 +1,9 @@ class ExerciseController < ApplicationController layout "base_courses" - before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit,:update] + before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show] before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] + helper :Exercise def index remove_invalid_exercise(@course) @@ -47,7 +48,8 @@ class ExerciseController < ApplicationController :time => "", :end_time => "", :publish_time => "", - :exercise_description => "" + :exercise_description => "", + :show_result => "" } @exercise = Exercise.create option if @exercise @@ -88,6 +90,7 @@ class ExerciseController < ApplicationController @exercise.time = params[:exercise][:time] @exercise.end_time = params[:exercise][:end_time] @exercise.publish_time = params[:exercise][:publish_time] + @exercise.publish_time = params[:exercise][:show_result] if @exercise.save respond_to do |format| format.js @@ -118,17 +121,18 @@ class ExerciseController < ApplicationController option = { :question_title => question_title, :question_type => params[:question_type] || 1, - :question_number => @exercise.exercise_questions.count + 1 + :question_number => @exercise.exercise_questions.count + 1, + :question_score => params[:question_score] } @exercise_questions = @exercise.exercise_questions.new option if params[:question_answer] for i in 1..params[:question_answer].count answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] question_option = { - :exercise_choice_id => i, - :answer_text => answer + :choice_position => i, + :choice_text => answer } - @exercise_questions.exercise_answers.new question_option + @exercise_questions.exercise_choices.new question_option end end # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 @@ -141,7 +145,7 @@ class ExerciseController < ApplicationController if @exercise_questions.save standart_answer = ExerciseStandardAnswer.new standart_answer.exercise_question_id = @exercise_questions.id - standart_answer.exercise_choice_id = params[:exercise_choice] + @exercise_questions.question_type == 3 ? standart_answer.answer_text = params[:exercise_choice] : standart_answer.exercise_choice_id = params[:exercise_choice] standart_answer.save respond_to do |format| format.js diff --git a/db/migrate/20151118014720_add_show_result_to_exercise.rb b/db/migrate/20151118014720_add_show_result_to_exercise.rb new file mode 100644 index 000000000..8148a277d --- /dev/null +++ b/db/migrate/20151118014720_add_show_result_to_exercise.rb @@ -0,0 +1,5 @@ +class AddShowResultToExercise < ActiveRecord::Migration + def change + add_column :exercises, :show_result, :integer + end +end diff --git a/db/migrate/20151118015638_add_question_score_to_exercise_question.rb b/db/migrate/20151118015638_add_question_score_to_exercise_question.rb new file mode 100644 index 000000000..a3235dcad --- /dev/null +++ b/db/migrate/20151118015638_add_question_score_to_exercise_question.rb @@ -0,0 +1,5 @@ +class AddQuestionScoreToExerciseQuestion < ActiveRecord::Migration + def change + add_column :exercise_questions, :question_score, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 25d561e86..8d506225f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151116071721) do +ActiveRecord::Schema.define(:version => 20151118015638) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -544,6 +544,7 @@ ActiveRecord::Schema.define(:version => 20151116071721) do t.integer "exercise_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.integer "question_score" end create_table "exercise_standard_answers", :force => true do |t| @@ -574,6 +575,7 @@ ActiveRecord::Schema.define(:version => 20151116071721) do t.datetime "updated_at", :null => false t.datetime "publish_time" t.datetime "end_time" + t.integer "show_result" end create_table "first_pages", :force => true do |t|