Sha256: 5b7930b61973aa04c5e78b3c2f5a07a6ba5e0402a57745479bad6f532f999edb

Contents?: true

Size: 761 Bytes

Versions: 3

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

class Avo::Views::ResourceNewComponent < ViewComponent::Base
  include Avo::ResourcesHelper
  include Avo::ApplicationHelper

  def initialize(
    resource: nil,
    model: nil
  )
    @resource = resource
    @model = model
  end

  def back_path
    if via_resource?
      helpers.resource_path(model: params[:via_relation_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_id])
    else
      helpers.resources_path(resource: @resource)
    end
  end

  private

  def via_resource?
    params[:via_relation_class].present? && params[:via_resource_id].present?
  end

  def relation_resource
    ::Avo::App.get_resource_by_model_name params[:via_relation_class].safe_constantize
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
avo-1.19.1.pre.2 app/components/avo/views/resource_new_component.rb
avo-1.19.1.pre.1 app/components/avo/views/resource_new_component.rb
avo-1.19.0 app/components/avo/views/resource_new_component.rb