Class: Course::Assessment::Question::ProgrammingController

Inherits:
Controller show all
Defined in:
app/controllers/course/assessment/question/programming_controller.rb

Instance Method Summary collapse

Methods included from ApplicationSignInCallbacksConcern

#sign_in

Methods included from ApplicationPaginationConcern

#page_param

Methods included from ApplicationAnnouncementsConcern

#global_announcements, #unread_global_announcements

Methods included from ApplicationInstanceUserConcern

#current_instance_user

Methods included from ApplicationUserTimeZoneConcern

#set_time_zone

Methods included from ApplicationUserConcern

#handle_access_denied, #publicly_accessible?

Methods included from ApplicationComponentsConcern

#handle_component_not_found

Instance Method Details

#createObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/course/assessment/question/programming_controller.rb', line 14

def create
  @template = 'course/assessment/question/programming/new.json.jbuilder'
  @programming_question.package_type =
    programming_question_params.key?(:file) ? :zip_upload : :online_editor
  process_package

  respond_to do |format|
    if @programming_question.save
      load_question_assessment
      format.json { render_success_json t('.success'), true }
    else
      format.json { render_failure_json t('.failure') }
    end
  end
end

#destroyObject


54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/course/assessment/question/programming_controller.rb', line 54

def destroy
  if @programming_question.destroy
    redirect_to course_assessment_path(current_course, @assessment),
                success: t('.success')
  else
    error = @programming_question.errors.full_messages.to_sentence
    redirect_to course_assessment_path(current_course, @assessment),
                danger: t('.failure', error: error)
  end
end

#editObject


30
31
32
33
# File 'app/controllers/course/assessment/question/programming_controller.rb', line 30

def edit
  @template = 'course/assessment/question/programming/edit.json.jbuilder'
  @meta = programming_package_service.extract_meta if @programming_question.edit_online?
end

#newObject


10
11
12
# File 'app/controllers/course/assessment/question/programming_controller.rb', line 10

def new
  @template = 'course/assessment/question/programming/new.json.jbuilder'
end

#updateObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/course/assessment/question/programming_controller.rb', line 35

def update
  result = @programming_question.class.transaction do
    @programming_question.assign_attributes programming_question_params
    @programming_question.skills.clear if programming_question_params[:skill_ids].blank?
    process_package

    raise ActiveRecord::Rollback unless @programming_question.save
    true
  end

  respond_to do |format|
    if result
      format.json { render_success_json t('.success'), false }
    else
      format.json { render_failure_json t('.failure') }
    end
  end
end