Sha256: 8a0c8a6cc77a44d08f8bad66febb0cb01987bf292f86a22091e4f81e8d2beeb3

Contents?: true

Size: 1.18 KB

Versions: 43

Compression:

Stored size: 1.18 KB

Contents

module Releaf::ActionController::Urls
  extend ActiveSupport::Concern

  included do
    helper_method :current_path, :index_path
  end

  # Returns path to redirect after successul resource create/update actions
  #
  # @return [String] path
  def success_path
    if create_another?
      url_for(action: :new, only_path: true)
    else
      url_for(action: :edit, id: @resource.id, only_path: true, index_path: index_path)
    end
  end

  # Returns index path for current request
  #
  # @return [String] path
  def index_path
    @index_path ||= resolve_index_path
  end

  def resolve_index_path
    # use current url
    if action_name == "index"
      current_path
    # use from get params
    elsif valid_index_path?(params[:index_path])
      params[:index_path]
    # fallback to index view
    else
      url_for(action: :index, only_path: true)
    end
  end

  def valid_index_path?(value)
    value.present? && value.is_a?(String) && value.first == "/"
  end

  # Returns current path without internal params
  #
  # @return String
  def current_path
    @current_path ||= [request.path, (request.query_parameters.to_query if request.query_parameters.present?)].compact.join("?")
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
releaf-core-3.1.0 app/lib/releaf/action_controller/urls.rb
releaf-core-3.0.3 app/lib/releaf/action_controller/urls.rb
releaf-core-3.0.2 app/lib/releaf/action_controller/urls.rb
releaf-core-3.0.1 app/lib/releaf/action_controller/urls.rb
releaf-core-3.0.0 app/lib/releaf/action_controller/urls.rb
releaf-core-2.2.1 app/lib/releaf/action_controller/urls.rb
releaf-core-2.2.0 app/lib/releaf/action_controller/urls.rb
releaf-core-2.1.2 app/lib/releaf/action_controller/urls.rb
releaf-core-2.1.1 app/lib/releaf/action_controller/urls.rb
releaf-core-2.1.0 app/lib/releaf/action_controller/urls.rb
releaf-core-2.0.1 app/lib/releaf/action_controller/urls.rb
releaf-core-2.0.0 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.22 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.21 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.20 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.19 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.18 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.17 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.16 app/lib/releaf/action_controller/urls.rb
releaf-core-1.1.15 app/lib/releaf/action_controller/urls.rb