Prismic and Ruby on rails: undefined method `[] 'for nil: NilClass when trying to get data from prismatic api
I am new to ruby ββand prism. I am trying to connect to the controller of my ruby ββon rails project to a prismatic api.
their tutorial shows the following code:
api = Prismic.api('https://your-repo-name.prismic.io/api')
doc = api.query(Prismic::Predicates.at("document.type", "page"))
content = doc.results
I set the prismatic gem correctly and put my repo name correctly. When I run my code, I get the following error:
NoMethodError in PageController#page
undefined method `[]' for nil:NilClass
for the line
doc = api.query(Prismic::Predicates.at("document.type", "page"))
I checked the value of the api variable and I got a # <Prismic::API:0x007fbcaaab6418>
in my api variable, so I think it works fine. I tried to change the predicates but didn't change anything.
If you know a way to solve this problem, I would be very grateful. Thank.
edit: page of my controller where the error occurred:
Class PageController < ApplicationController
def page
api = Prismic.api('https://xxx.prismic.io/api')
puts 'api ='
puts api
puts '==was api'
doc = api.query(Prismic::Predicates.at("document.tags", ["conseil"]))
content = doc.results
puts 'content'
@test1 = 'test'#content[0]['id']
end
end
+3
source to share
No one has answered this question yet
Check out similar questions: