修改创建方式

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 class ExerciseController < ApplicationController
layout "base_courses" 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] before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list,:edit]
def index def index
@is_teacher = User.current.allowed_to?(:as_teacher,@course) @is_teacher = User.current.allowed_to?(:as_teacher,@course)
if @is_teacher if @is_teacher
@ -36,9 +38,19 @@ class ExerciseController < ApplicationController
end end
def new def new
@exercise = Exercise.new option = {
respond_to do |format| :exercise_name => "",
format.html{render :layout => 'base_courses'} :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
end end
@ -71,10 +83,10 @@ class ExerciseController < ApplicationController
end end
def update def update
@exercise.exercise_name = params[:exercise_name] @exercise.exercise_name = params[:exercise][:exercise_name]
@exercise.exercise_description = params[:exercise_name] @exercise.exercise_description = params[:exercise][:exercise_description]
@exercise.start_at = params[:start_at] @exercise.time = params[:exercise][:time]
@exercise.end_at = params[:end_at] @exercise.end_time = params[:exercise][:end_time]
if @exercise.save if @exercise.save
respond_to do |format| respond_to do |format|
format.js format.js
@ -218,6 +230,13 @@ class ExerciseController < ApplicationController
end end
private 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 def find_course
@course = Course.find params[:course_id] @course = Course.find params[:course_id]
rescue Exception => e rescue Exception => e