Module: ActiveRecordSurveyApi::Concerns::Controllers::Answers
- Extended by:
- ActiveSupport::Concern
- Included in:
- AnswersController, Concerns::Controllers::Answers
- Defined in:
- lib/active_record_survey_api/concerns/controllers/answers.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/active_record_survey_api/concerns/controllers/answers.rb', line 39 def create @survey = @question.survey if @survey.nil? @answer = new_answer(answer_params) @question.build_answer(@answer, @survey) @survey.save render json: serialize_model(@answer, serializer: ActiveRecordSurveyApi::AnswerSerializer) end |
#destroy ⇒ Object
32 33 34 35 36 37 |
# File 'lib/active_record_survey_api/concerns/controllers/answers.rb', line 32 def destroy @answer = answer_by_id(params[:id]) @answer.destroy head :no_content end |
#index ⇒ Object
20 21 22 23 24 |
# File 'lib/active_record_survey_api/concerns/controllers/answers.rb', line 20 def index @answers = all_answers render json: serialize_models(@answers, serializer: ActiveRecordSurveyApi::AnswerSerializer, meta: { total: @answers.length }) end |
#show ⇒ Object
26 27 28 29 30 |
# File 'lib/active_record_survey_api/concerns/controllers/answers.rb', line 26 def show @answer = answer_by_id(params[:id]) render json: serialize_model(@answer, serializer: ActiveRecordSurveyApi::AnswerSerializer) end |
#update ⇒ Object
13 14 15 16 17 18 |
# File 'lib/active_record_survey_api/concerns/controllers/answers.rb', line 13 def update @answer = answer_by_id(params[:id]) @answer.update_attributes(answer_params) render json: serialize_model(@answer, serializer: ActiveRecordSurveyApi::AnswerSerializer) end |