Module: Koi::Extensions::ObjectRendering

Defined in:
lib/koi/extensions/object_rendering.rb

Instance Method Summary collapse

Instance Method Details

#merge_prefix_into_object_path(prefix, object_path) ⇒ Object

Workaround for de-duplicating nested module paths for admin controllers See github.com/rails/rails/issues/50916



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/koi/extensions/object_rendering.rb', line 8

def merge_prefix_into_object_path(prefix, object_path)
  if prefix.include?(?/) && object_path.include?(?/)
    prefixes     = []
    prefix_array = File.dirname(prefix).split("/")

    prefix_array.each_with_index do |dir, index|
      break if object_path.start_with?(prefix_array[index..].join("/"))

      prefixes << dir
    end

    (prefixes << object_path).join("/")
  else
    object_path
  end
end