Sha256: 4468326358d9ed05120b884e987506d6ae874ae7b6de4f96e18ba64bd48d6756
Contents?: true
Size: 1.71 KB
Versions: 5
Compression:
Stored size: 1.71 KB
Contents
# frozen_string_literal: true class Avo::Views::ResourceEditComponent < Avo::ResourceComponent include Avo::ResourcesHelper include Avo::ApplicationHelper attr_reader :view def initialize(resource: nil, model: nil, actions: [], view: :edit) @resource = resource @model = model @actions = actions @view = view split_panel_fields end def title @resource.default_panel_name 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]) elsif via_index? helpers.resources_path(resource: @resource) else # via resource show page if is_edit? helpers.resource_path(model: @resource.model, resource: @resource) else helpers.resources_path(resource: @resource) end 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 @view, raise_exception: false end private def via_index? params[:via_view] == "index" end def is_edit? view == :edit end def form_method return :put if is_edit? :post end def form_url if is_edit? helpers.resource_path( model: @resource.model, resource: @resource ) else helpers.resources_path( resource: @resource, via_relation_class: params[:via_relation_class], via_relation: params[:via_relation], via_resource_id: params[:via_resource_id] ) end end end
Version data entries
5 entries across 5 versions & 1 rubygems