5

I'm quite new to ruby and prismic. I'm trying to connect on the controller of my ruby on rails project to the prismic api.

their tutorial show 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 installed the prismic 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 api variable value and i get #<Prismic::API:0x007fbcaaab6418> in my api variable, so i guess it's working fine. I tried to change the predicates but it's doesn't change anything.

If you know a way to solve this problem i would be very gratefull. Thanks.

edit: my controller page where the error occurs :

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
tim
  • 51
  • 5

0 Answers0