Rails: Share template between ActiveAdmin namespaces
Appearance
Problem
How to share a template between ActiveAdmin namespaces, with links linking back to the correct namespace?
Solution
# ./app/views/shared/_organisation_contacts.html.arb
# NOTE: Explicit call raises exception if undefined, which is good :)
# See: https://stackoverflow.com/questions/12894839/document-partial-parameters-in-rails#answer-12976723
# Parameters:
person
namespaceProblem is that links should link back to their own namespace. Solved by building links like this:
link = send("#{namespace}_organisation_path", oc.organisation&.id)
organisation = link_to(title.html_safe, link)Calls to the template are identical, except they originate from a different namespace (admin, user):
# ./app/admin/people.rb & ./app/user/people.rb
render partial: 'shared/organisation_contacts',
locals: { person: person, namespace: active_admin_namespace.route_prefix }