修改创建方式

This commit is contained in:
huang 2015-11-17 19:29:25 +08:00
parent 9935cfea44
commit 3cdda2a60a
1 changed files with 26 additions and 7 deletions

View File

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