修改添加题目相关

This commit is contained in:
huang 2015-11-18 10:46:56 +08:00
parent 02db1b7e14
commit 282c7f5bd2
4 changed files with 24 additions and 8 deletions

View File

@ -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

View File

@ -0,0 +1,5 @@
class AddShowResultToExercise < ActiveRecord::Migration
def change
add_column :exercises, :show_result, :integer
end
end

View File

@ -0,0 +1,5 @@
class AddQuestionScoreToExerciseQuestion < ActiveRecord::Migration
def change
add_column :exercise_questions, :question_score, :integer
end
end

View File

@ -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|