Module: Avo::UrlHelpers

Included in:
ApplicationController, TabSwitcherComponent
Defined in:
app/helpers/avo/url_helpers.rb

Instance Method Summary collapse

Instance Method Details

#edit_resource_path(record:, resource:, **args) ⇒ Object



49
50
51
# File 'app/helpers/avo/url_helpers.rb', line 49

def edit_resource_path(record:, resource:, **args)
  avo.send :"edit_resources_#{resource.singular_route_key}_path", record, **args
end

#new_resource_path(resource:, **args) ⇒ Object



45
46
47
# File 'app/helpers/avo/url_helpers.rb', line 45

def new_resource_path(resource:, **args)
  avo.send :"new_resources_#{resource.singular_route_key}_path", **args
end

#preview_resource_path(resource:, **args) ⇒ Object



38
39
40
41
42
43
# File 'app/helpers/avo/url_helpers.rb', line 38

def preview_resource_path(
  resource:,
  **args
)
  avo.send :"preview_resources_#{resource.singular_route_key}_path", resource.record, **args
end


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/avo/url_helpers.rb', line 66

def related_resources_path(
  parent_record,
  record,
  keep_query_params: false,
  **args
)
  return if record.nil?

  existing_params = {}

  begin
    if keep_query_params
      existing_params =
        Addressable::URI.parse(request.fullpath).query_values.symbolize_keys
    end
  rescue
  end

  avo.resources_associations_index_path(parent_record.model_name.route_key, record.to_param, **existing_params, **args)
end

#resource_attach_path(resource, record_id, related_name, related_id = nil) ⇒ Object



53
54
55
# File 'app/helpers/avo/url_helpers.rb', line 53

def resource_attach_path(resource, record_id, related_name, related_id = nil)
  helpers.avo.resources_associations_new_path(resource.singular_route_key, record_id, related_name)
end

#resource_detach_path(model_name, record_id, related_name, related_id = nil) ⇒ Object



57
58
59
60
61
62
63
64
# File 'app/helpers/avo/url_helpers.rb', line 57

def resource_detach_path(
  model_name, # teams
  record_id, # 1
  related_name, # admin
  related_id = nil
)
  avo.resources_associations_destroy_path(model_name, record_id, related_name, related_id)
end

#resource_path(record:, resource:, resource_id: nil, keep_query_params: false, **args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/avo/url_helpers.rb', line 22

def resource_path(
  record:,
  resource:,
  resource_id: nil,
  keep_query_params: false,
  **args
)
  if record.respond_to? :id
    id = record
  elsif resource_id.present?
    id = resource_id
  end

  avo.send :"resources_#{resource.singular_route_key}_path", id, **args
end

#resource_view_path(**args) ⇒ Object



87
88
89
90
91
92
93
# File 'app/helpers/avo/url_helpers.rb', line 87

def resource_view_path(**args)
  if Avo.configuration.resource_default_view.edit?
    edit_resource_path(**args)
  else
    resource_path(**args)
  end
end

#resources_path(resource:, keep_query_params: false, **args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/avo/url_helpers.rb', line 3

def resources_path(resource:, keep_query_params: false, **args)
  return if resource.nil?

  existing_params = {}
  if keep_query_params
    begin
      existing_params =
        Addressable::URI.parse(request.fullpath).query_values.symbolize_keys
    rescue
    end
  end

  route_key = resource.route_key
  # Add the `_index` suffix for the uncountable names so they get the correct path (`fish_index`)
  route_key << "_index" if resource.route_key == resource.singular_route_key

  avo.send :"resources_#{route_key}_path", **existing_params, **args
end