How to get prismic document in draft state using the the ruby gem


How I can get a Prismic Document in a draft state using the ruby gem?

I'm implementing the Preview.

Hey there @mohamed, previews work with a particular document ref. You'd need to find the correct ref to find the draft document:

Thanks to pointing that out.

I'm going to share the solution in case somebody gets stuck with it:

When pressing the preview button:

You will get redirected to a page like:

Then the Prismic API request that you need to do is:

query = ["document.type", "my_doc")]"", params[:documentId]) # "Yg4X4RIGACoAw1qA"
query_options = {
  lang: "en-gb",
  ref: params[:token] # ""

prismic_api = Prismic.api("", access_token: "...")
document = prismic_api.query(query, query_options).results.first