Module: ActiveRecordSurveyApi::Concerns::Controllers::Questions

Extended by:
ActiveSupport::Concern
Included in:
QuestionsController, Concerns::Controllers::Questions
Defined in:
lib/active_record_survey_api/concerns/controllers/questions.rb

Instance Method Summary collapse

Instance Method Details

#createObject



37
38
39
40
41
42
43
# File 'lib/active_record_survey_api/concerns/controllers/questions.rb', line 37

def create
  @question = new_question(question_params)
  @survey.build_question(@question)
  @survey.save

  render json: serialize_model(@question, serializer: ActiveRecordSurveyApi::QuestionSerializer)
end

#destroyObject



23
24
25
26
27
28
# File 'lib/active_record_survey_api/concerns/controllers/questions.rb', line 23

def destroy
  @question = question_by_id(params[:id])
  @question.destroy

  head :no_content
end

#indexObject



11
12
13
14
15
# File 'lib/active_record_survey_api/concerns/controllers/questions.rb', line 11

def index
  @questions = all_questions

  render json: serialize_models(@questions, serializer: ActiveRecordSurveyApi::QuestionSerializer, meta: { total: @questions.length })
end

#showObject



17
18
19
20
21
# File 'lib/active_record_survey_api/concerns/controllers/questions.rb', line 17

def show
  @question = question_by_id(params[:id])

  render json: serialize_model(@question, serializer: ActiveRecordSurveyApi::QuestionSerializer)
end

#updateObject



30
31
32
33
34
35
# File 'lib/active_record_survey_api/concerns/controllers/questions.rb', line 30

def update
  @question = question_by_id(params[:id])
  @question.update_attributes(question_params)

  render json: serialize_model(@question, serializer: ActiveRecordSurveyApi::QuestionSerializer)
end