Hello,
How I can get a Prismic Document in a draft
state using the ruby gem?
I'm implementing the Preview.
Hello,
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:
http://example.com/preview?token=https%3A%2F%2Fexample.prismic.io%2Fpreviews%2FYg4VNhIXVC0Aw05Y%3AYg4X4RIAACoAw1qB%3FwebsitePreviewId%3DYg0j4RIACCwAvwW1&documentId=Yg4X4RIGACoAw1qA
Then the Prismic API request that you need to do is:
query = [
Prismic::Predicates.at("document.type", "my_doc")]
Prismic::Predicates.at("document.id", params[:documentId]) # "Yg4X4RIGACoAw1qA"
]
query_options = {
lang: "en-gb",
ref: params[:token] # "https://example.prismic.io/previews/Yg4VNhIXVC0Aw05Y:Yg4X4RIAACoAw1qB?websitePreviewId=Yg0j4RIACCwAvwW1"
}.with_indifferent_access
prismic_api = Prismic.api("https://example.cdn.prismic.io/api", access_token: "...")
document = prismic_api.query(query, query_options).results.first