Search code examples
ruby-on-railsactiveadminhas-manymodel-associations

List all associations as links in active admin


Is it possible in active admin to list all of the has_many associations of my record as links?

The code should look something like:

column "belongs to" do |b|
    b.associations.map { |a| link_to(a.name, admin_association_path(a) }
end

But this generates a list of tags that aren't rendered as clickable links.


Solution

  • map is producing an array of html strings, so you need to join them to get a single string and then mark it as html-safe.

    column "belongs to" do |b|
        b.associations
         .map { |a| link_to(a.name, admin_association_path(a)) }
         .join
         .html_safe
    end