Sha256: 2892ec4374b3f2d2b741067dfdd79f7bbf30d20e61b540dfa9b2da0bf87c6928

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

# This responder modifies your current responder to redirect
# to the collection page on POST/PUT/DELETE if you use save, not for 'continue'.
module Auxilium
  module ContinueResponder
    protected

    def navigation_location
      return options[:location] if options[:location] && (defined?(Devise) && (controller.is_a?(Devise::SessionsController) || controller.is_a?(Devise::PasswordsController)))
      return options[:location] if controller.params[:commit] == 'continue' && options[:location]
      return options[:collection_location].call if %w[save commit delete].include?(controller.params[:commit]) && options[:collection_location]
      return resource_location if controller.params[:commit] == 'continue'

      klass = resources.last.class

      if klass.respond_to?(:model_name)
        resources[0...-1] << klass.model_name.route_key.to_sym
      else
        resources
      end
    end

    def navigation_behavior(error)
      if get?
        raise error
      elsif has_errors? && options[:error_location]
        redirect_to options[:error_location].call, status: :see_other
      elsif has_errors? && default_action
        render error_rendering_options
      else
        redirect_to navigation_location, status: :see_other
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auxilium-3.0.31 lib/auxilium/responders/continue_responder.rb
auxilium-3.0.30 lib/auxilium/responders/continue_responder.rb