Sha256: 6677d71f742bdab6437ed73cec4d0ecd3be720ab0b8a7a0924d602871d53695e

Contents?: true

Size: 941 Bytes

Versions: 52

Compression:

Stored size: 941 Bytes

Contents

# frozen_string_literal: true

class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
  include Avo::ResourcesHelper
  include Avo::ApplicationHelper

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

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

  # The save button is dependent on the edit? policy method.
  # The update? method should be called only when the user clicks the Save button so the developer gets access to the params from the form.
  def can_see_the_save_button?
    @resource.authorization.authorize_action :edit, raise_exception: false
  end

  private

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

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
avo-1.25.2 app/components/avo/views/resource_edit_component.rb
avo-2.5.2.pre.7 app/components/avo/views/resource_edit_component.rb
avo-2.5.2.pre.2 app/components/avo/views/resource_edit_component.rb
avo-2.5.2.pre.1 app/components/avo/views/resource_edit_component.rb
avo-2.5.1 app/components/avo/views/resource_edit_component.rb
avo-2.5.0 app/components/avo/views/resource_edit_component.rb
avo-2.4.1 app/components/avo/views/resource_edit_component.rb
avo-2.4.0 app/components/avo/views/resource_edit_component.rb
avo-2.3.1.pre.6 app/components/avo/views/resource_edit_component.rb
avo-2.3.1.pre.5 app/components/avo/views/resource_edit_component.rb
avo-2.3.1.pre.4 app/components/avo/views/resource_edit_component.rb
avo-2.3.1.pre.3 app/components/avo/views/resource_edit_component.rb
avo-2.3.1.pre.2 app/components/avo/views/resource_edit_component.rb
avo-2.3.1.pre.1 app/components/avo/views/resource_edit_component.rb
avo-2.3.0 app/components/avo/views/resource_edit_component.rb
avo-2.2.2 app/components/avo/views/resource_edit_component.rb
avo-2.2.1 app/components/avo/views/resource_edit_component.rb
avo-2.2.0 app/components/avo/views/resource_edit_component.rb
avo-2.1.2.pre2 app/components/avo/views/resource_edit_component.rb
avo-2.1.2.pre1 app/components/avo/views/resource_edit_component.rb