Sha256: fa9c96f263e6b4136d868fa4424ccf82ced43e5ce17f60606b23e06cba0e8330

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class SurveysController < Lcms::Engine::ApplicationController
      skip_before_action :check_user_has_survey_filled_in

      def create
        @form = SurveyForm.new(permitted_params)
        if @form.valid?
          current_user.update(survey: @form.attributes)
          notify_heap
          loc = stored_location_for(:user)
          loc = root_path if loc.is_a?(String) && loc[survey_path]
          redirect_to loc || root_path
        else
          render :show
        end
      end

      def show
        return redirect_to root_path if current_user.ready_to_go?

        @form = SurveyForm.new(current_user.survey)
      end

      private

      def notify_heap
        data = current_user
                 .survey.except('first_name', 'last_name')
                 .merge(
                   access_code: current_user.access_code,
                   email: current_user.email
                 )
        Heap.add_user_properties current_user.id, data
      end

      def permitted_params
        params.require(:survey_form).permit(
          :additional_period,
          :additional_period_minutes,
          :district_or_system,
          :district_or_system_other,
          :first_name,
          :last_name,
          :number_of_minutes,
          :prior_experience,
          :subject_or_grade,
          :subject_or_grade_other
        )
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lcms-engine-0.1.4 app/controllers/lcms/engine/surveys_controller.rb
lcms-engine-0.1.3 app/controllers/lcms/engine/surveys_controller.rb
lcms-engine-0.2.0 app/controllers/lcms/engine/surveys_controller.rb
lcms-engine-0.1.2 app/controllers/lcms/engine/surveys_controller.rb
lcms-engine-0.1.0 app/controllers/lcms/engine/surveys_controller.rb