Merge branch 'sw_new_course' of http://repository.trustie.net/xianbo/trustie2 into sw_new_course

This commit is contained in:
cxt 2015-11-18 11:14:34 +08:00
commit c5c16e25b6
4 changed files with 27 additions and 7 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
include ExerciseHelper
def index
@ -48,7 +49,8 @@ class ExerciseController < ApplicationController
:time => "",
:end_time => "",
:publish_time => "",
:exercise_description => ""
:exercise_description => "",
:show_result => ""
}
@exercise = Exercise.create option
if @exercise
@ -89,6 +91,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
@ -119,17 +122,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 = {
:answer_position => 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
@ -140,6 +144,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
@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
end

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|