Module: ActiveRecordSurveyApi::Concerns::Controllers::Surveys
- Extended by:
- ActiveSupport::Concern
- Included in:
- SurveysController
- Defined in:
- lib/active_record_survey_api/concerns/controllers/surveys.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edges ⇒ Object
- #index ⇒ Object
- #nodes ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/active_record_survey_api/concerns/controllers/surveys.rb', line 33 def create @survey = new_survey(survey_params) @survey.save #render json: @survey, serializer: SurveySerializer render json: serialize_model(@survey, serializer: ActiveRecordSurveyApi::SurveySerializer) end |
#destroy ⇒ Object
19 20 21 22 23 24 |
# File 'lib/active_record_survey_api/concerns/controllers/surveys.rb', line 19 def destroy @survey = survey_by_id(params[:id]) @survey.destroy head :no_content end |
#edges ⇒ Object
41 42 43 44 45 |
# File 'lib/active_record_survey_api/concerns/controllers/surveys.rb', line 41 def edges @survey = survey_by_id(params[:survey_id]) render json: @survey.edges end |
#index ⇒ Object
7 8 9 10 11 |
# File 'lib/active_record_survey_api/concerns/controllers/surveys.rb', line 7 def index @surveys = all_surveys render json: serialize_models(@surveys, serializer: ActiveRecordSurveyApi::SurveySerializer, meta: { total: @surveys.length }) end |
#nodes ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_record_survey_api/concerns/controllers/surveys.rb', line 47 def nodes @survey = survey_by_id(params[:survey_id]) nodes = @survey.nodes.includes(:translations) questions = nodes.select { |i| i.class.ancestors.include?(::ActiveRecordSurvey::Node::Question) } answers = nodes.select { |i| i.class.ancestors.include?(::ActiveRecordSurvey::Node::Answer) } questions = serialize_models(questions, serializer: ActiveRecordSurveyApi::QuestionSerializer, meta: { total: questions.length }) answers = serialize_models(answers, serializer: ActiveRecordSurveyApi::AnswerSerializer, meta: { total: answers.length }) render json: { questions: questions, answers: answers } end |
#show ⇒ Object
13 14 15 16 17 |
# File 'lib/active_record_survey_api/concerns/controllers/surveys.rb', line 13 def show @survey = survey_by_id(params[:id]) render json: serialize_model(@survey, serializer: ActiveRecordSurveyApi::SurveySerializer) end |
#update ⇒ Object
26 27 28 29 30 31 |
# File 'lib/active_record_survey_api/concerns/controllers/surveys.rb', line 26 def update @survey = survey_by_id(params[:id]) @survey.update_attributes(survey_params) render json: serialize_model(@survey, serializer: ActiveRecordSurveyApi::SurveySerializer) end |