Class: ActiveRecordSurveyApi::QuestionsController

Inherits:
ApplicationController show all
Includes:
Concerns::Controllers::Questions
Defined in:
app/controllers/active_record_survey_api/questions_controller.rb

Instance Method Summary collapse

Methods included from Concerns::Controllers::Questions

#all_questions, #find_survey, #json_params, #new_question, #question_by_id, #question_params

Instance Method Details

#createObject



27
28
29
30
31
32
33
# File 'app/controllers/active_record_survey_api/questions_controller.rb', line 27

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

	render json: @question, serializer: QuestionSerializer
end

#indexObject



15
16
17
18
19
# File 'app/controllers/active_record_survey_api/questions_controller.rb', line 15

def index
	@questions = all_questions

	render json: @questions, each_serializer: QuestionSerializer, meta: { total: @questions.length }
end

#showObject



21
22
23
24
25
# File 'app/controllers/active_record_survey_api/questions_controller.rb', line 21

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

	render json: @question, serializer: QuestionSerializer
end