Sha256: e547e915c8867f572021a99fced4f68c1838838f7d8ae2870f9f74e4a72a7206

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

module Effective
  class EventRegistrationsController < ApplicationController
    before_action(:authenticate_user!) if defined?(Devise)

    include Effective::WizardController

    resource_scope -> {
      event = Effective::Event.find(params[:event_id])
      EffectiveEvents.EventRegistration.deep.where(owner: current_user, event: event)
    }

    # Allow only 1 in-progress event registration at a time
    before_action(only: [:new, :show], unless: -> { resource&.done? }) do
      existing = resource_scope.in_progress.where.not(id: resource).first

      if existing.present?
        flash[:success] = "You have been redirected to your existing in progress event registration"
        redirect_to effective_events.event_event_registration_build_path(existing.event, existing, existing.next_step)
      end
    end

    after_save do
      flash.now[:success] = ''
    end

    # The default redirect doesn't respect nested resources here
    def new
      self.resource ||= (find_wizard_resource || resource_scope.new)
      EffectiveResources.authorize!(self, :new, resource)

      redirect_to effective_events.event_event_registration_build_path(
        resource.event,
        (resource.to_param || :new),
        (resource.first_uncompleted_step || resource_wizard_steps.first)
      )
    end

    private

    def permitted_params
      model = (params.key?(:effective_event_registration) ? :effective_event_registration : :event_registration)

      params.require(model).permit!.except(:status, :status_steps, :wizard_steps, :submitted_at)
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
effective_events-0.1.10 app/controllers/effective/event_registrations_controller.rb
effective_events-0.1.9 app/controllers/effective/event_registrations_controller.rb
effective_events-0.1.8 app/controllers/effective/event_registrations_controller.rb
effective_events-0.1.7 app/controllers/effective/event_registrations_controller.rb
effective_events-0.1.6 app/controllers/effective/event_registrations_controller.rb
effective_events-0.1.5 app/controllers/effective/event_registrations_controller.rb