Class: Course::Survey::QuestionsController

Inherits:
Controller show all
Defined in:
app/controllers/course/survey/questions_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


5
6
7
8
9
10
11
12
13
# File 'app/controllers/course/survey/questions_controller.rb', line 5

def create
  last_weight = @survey.questions.maximum(:weight)
  @question.weight = last_weight ? last_weight + 1 : 0
  if @question.save
    render_question_json
  else
    render json: { errors: @question.errors }, status: :bad_request
  end
end

#destroyObject


23
24
25
26
27
28
29
# File 'app/controllers/course/survey/questions_controller.rb', line 23

def destroy
  if @question.destroy
    head :ok
  else
    head :bad_request
  end
end

#updateObject


15
16
17
18
19
20
21
# File 'app/controllers/course/survey/questions_controller.rb', line 15

def update
  if @question.update_attributes(question_params)
    render_question_json
  else
    render json: { errors: @question.errors }, status: :bad_request
  end
end