How to display a list of all tags used across different types of documents

I’m using prismic with Rails and having trouble returning a list of all tags in order to populate a sidebar navigation. I can do something like this:

@all_posts = api.query(
      ["document.type", ["analysis", "blog", "data_viz", "news", "report" ]) ],
        "page" => page,
        "orderings" => "[document.first_publication_date desc]",
        "ref" => ref

<% if @all_posts %>
        <% @all_posts.each do |post| %>
          <%= post.tags %>
        <% end %>
<% end %>

That will iterate through every post and return an array of tags for each post, but how do you only return a list of all the tags used across all different types of documents (and list them only once)? Is there a way to do this with the prismic api?

Hello Lee!

When querying the response API from the endpoint, the first thing you’ll see is the response object, in there you can find various sets of information about your repository, including the list of existing tags. Read about The response object in Ruby.

Thanks Paulina. Once you’ve gotten the response object, how would you access the tags and iterate through them? That’s where I’m confused.

Your Prismic endpoint must be similar to this one The CDN will allow you to access to key properties of your endpoint, including the ones I mentioned before (the response object data).

We don’t have an example that shows exactly how to do this but I’d suggest you save the list or array of tags in a constant that you can later use to iterate/compare with the matching tags of the retrieved documents depending on the page you’re at or the filters you’re adding into your page.

Thanks. Could this also be the root of this unrelated issue:

I took the Prismic Starter Rails app and upgraded it from Rails 4 to 6:

And, that Prismic Start Rails app had this endpoint in config/prismic.yml:

If updating that to this is needed, that would explain a lot of things I found confusing about the docs:


Update on this. I’m using the prismic ruby example app as a starting point and when I tried to update my api endpoint in config/prismic.yml to this:

Suddenly I can’t use getSingle:

This doesn’t seem right. When I visit the endpoint it looks identical to this:

But the only thing that works is the old version of the api endpoint. Any thoughts on why this might be?

Hi Lee,

Sorry about that, the V2 of the API doesn’t currently work with Ruby apps, so you can continue using V1 with this URL

The tip Paulina suggested for getting the tags with the CDN endpoint will still work with this endpoint though.


@Phil Thanks for the clarification. Any plans to upgrade the prismic Ruby gem to keep up with the latest version of the API?

Seems like Ruby is slowly getting sunsetted by Prismic.

I’d like to continue using Prismic with Rails, but don’t want to invest new projects in that direction if it’s not going to be supported well down the road.

Hey Lee,

Sorry I never got back to you on that last question, this slipped away from me. I'm not sure about what the teams status is on the Ruby kit. I know they are actively working on it, but I'm not sure of the support for V2 of the API.

I've reached out to them and will get back to you once I know more.