Sha256: feab2cadd9d0efa8bbf6534f0d42cd149c9e231074da63eb5d0235536de9ca9e

Contents?: true

Size: 973 Bytes

Versions: 6

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

module Responders
  # This responder modifies your current responder to redirect
  # to the collection page on POST/PUT/DELETE.
  module CollectionResponder
    protected

    # Returns the collection location for redirecting after POST/PUT/DELETE.
    # This method, converts the following resources array to the following:
    #
    #   [:admin, @post] #=> [:admin, :posts]
    #   [@user, @post]  #=> [@user, :posts]
    #
    # When these new arrays are given to redirect_to, it will generate the
    # proper URL pointing to the index action.
    #
    #   [:admin, @post] #=> admin_posts_url
    #   [@user, @post]  #=> user_posts_url(@user.to_param)
    #
    def navigation_location
      return options[:location] if options[:location]

      klass = resources.last.class

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

Version data entries

6 entries across 5 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/responders-3.1.1/lib/responders/collection_responder.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/responders-3.1.1/lib/responders/collection_responder.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/responders-3.1.1/lib/responders/collection_responder.rb
jets-responders-0.1.0 lib/responders/collection_responder.rb
responders-3.1.1 lib/responders/collection_responder.rb
responders-3.1.0 lib/responders/collection_responder.rb