Allow using table actions in different namespaces

This way we can reuse it in sections like SDGManagement and URLs will be
automatically generated as expected.
This commit is contained in:
Javi Martín
2021-01-07 17:49:24 +01:00
parent 2968275a1c
commit c66a5a30ef
10 changed files with 63 additions and 14 deletions

View File

@@ -16,14 +16,23 @@ module ActionDispatch::Routing::UrlFor
end
def admin_polymorphic_path(resource, options = {})
namespaced_polymorphic_path(:admin, resource, options)
end
def sdg_management_polymorphic_path(resource, options = {})
namespaced_polymorphic_path(:sdg_management, resource, options)
end
def namespaced_polymorphic_path(namespace, resource, options = {})
if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer
Poll::Question Poll::Question::Answer::Video Poll::Shift].include?(resource.class.name)
Poll::Question Poll::Question::Answer::Video Poll::Shift
SDG::LocalTarget].include?(resource.class.name)
resolve = resolve_for(resource)
resolve_options = resolve.pop
polymorphic_path([:admin, *resolve], options.merge(resolve_options))
polymorphic_path([namespace, *resolve], options.merge(resolve_options))
else
polymorphic_path([:admin, *resource_hierarchy_for(resource)], options)
polymorphic_path([namespace, *resource_hierarchy_for(resource)], options)
end
end