Class: Course::Assessment::Question::Controller

Inherits:
ComponentController show all
Defined in:
app/controllers/course/assessment/question/controller.rb

Class Method Summary collapse

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

Class Method Details

.build_and_authorize_new_question(question_name, options) ⇒ Object

Use method to build new questions.

Cancancan uses assessment.specific_questions.build to build a resource, which will break since the specific questions are nested through question_assessments and AR does not support build associations with nested has_many through.


10
11
12
13
14
15
16
17
18
# File 'app/controllers/course/assessment/question/controller.rb', line 10

def self.build_and_authorize_new_question(question_name, options)
  before_action only: options[:only], except: options[:except] do
    question = options[:class].new
    question.question_assessments.build(assessment: @assessment)
    question.assign_attributes(send("#{question_name}_params")) if action_name != 'new'
    authorize!(action_name.to_sym, question)
    instance_variable_set("@#{question_name}", question) unless instance_variable_get("@#{question_name}")
  end
end

Instance Method Details

#authorize_assessmentObject (protected)


26
27
28
# File 'app/controllers/course/assessment/question/controller.rb', line 26

def authorize_assessment
  authorize!(:update, @assessment)
end

#load_question_assessment_for(question) ⇒ Object


20
21
22
# File 'app/controllers/course/assessment/question/controller.rb', line 20

def load_question_assessment_for(question)
  @assessment.question_assessments.find_by!(question: question.acting_as)
end