简体   繁体   English

STORYBLOK,RUBY:nil:NilClass (NoMethodError) 的未定义方法“[]”

[英]STORYBLOK, RUBY: undefined method `[]' for nil:NilClass (NoMethodError)

I don't know that much about RUBY , just thought that you guys might help me with this.我不太了解RUBY ,只是觉得你们可能会帮助我。 I'm using Storyblok as my headless CMS and JEKYLL when I'm building serve it this is the error that I got;我在构建服务时使用 Storyblok 作为我的无头 CMS 和 JEKYLL 这是我得到的错误;

33: from C:/project/test/_plugins/storyblok_generator.rb:8:in `generate'
32: from C:/project/test/_plugins/storyblok_cms/generator.rb:12:in `generate!'
C:/project/test/vendor/cache/ruby/2.7.0/gems/storyblok-3.0.1/lib/storyblok/client.rb:354:in `block (2 levels) in find_and_fill_links': undefined method `[]' for nil:NilClass (NoMethodError)

the code below is from _plugins/storyblok_cms/generator.rb下面的代码来自_plugins/storyblok_cms/generator.rb

def generate!
  timestamp = Time.now.to_i
  links = client.links(cv: timestamp)['data']['links']
  stories = client.stories(per_page: 100, page: 1, cv: timestamp)['data']['stories']   #line 12

  stories.each do |story|
    # create all pages except global (header,footer,etc.)
    content_type = story['content']['component']
    if content_type != 'shared'
      site.pages << create_page(site, story, links)
    end
    rescue UnknownContentTypeError => e
    # for production, raise unknown content type error;
    # for preview and other environments, issue an warning only since the content_type might be available
    # but the code handling that content type might be in a different branch.
    Jekyll.env == 'production' ? raise :  Jekyll.logger.warn(e.message)
  end

  site.data['stories'] = stories
  site.data['articles'] = stories.select { |story| story['full_slug'].start_with?('articles') }
  site.data['shared'] = stories.select { |story| story['full_slug'].start_with?('shared') }
end

the code below is from _plugins/storyblok_generator.rb下面的代码来自_plugins/storyblok_generator.rb

require "storyblok"

module Jekyll
  class StoryblokGenerator < Jekyll::Generator
    safe true

    def generate(site)
      StoryblokCms::Generator.new(site).generate!   #line 8
    end
  end
end

Additional Info:附加信息:

  • ruby version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32] ruby 版本: ruby 2.7.4p191(2021-07-07 修订版 a21a3b7d23)[x64-mingw32]
  • jekyll version: jekyll 4.2.1杰基尔版本:杰基尔 4.2.1
  • OS : Windows 10操作系统:Windows 10

I've actually found the solution to this, So this error occurs because I have created a page template in Block Library in Storyblok and then firing bundle exec jekyll serve command in terminal without creating the page template source/file in my project directory.我实际上已经找到了解决方案,所以出现此错误是因为我在 Storyblok 的 Block Library 中创建了一个页面模板,然后在终端中触发了bundle exec jekyll serve命令,而没有在我的项目目录中创建页面模板源/文件。

So I have an about_us block (content-type) in Block Library created and then when I fire bundle exec jekyll serve without creating an about_us.html first in _layouts folder, It would trigger the error.所以我在块库中创建了一个about_us块(内容类型),然后当我在没有先在_layouts文件夹中创建about_us.html的情况下启动bundle exec jekyll serve jekyll serve 时,它会触发错误。

Solution;解决方案;
Make sure to create the source/file first in the _layouts folder if you have created a block (content-type) in block library.如果您在块库中创建了块(内容类型),请确保首先在_layouts文件夹中创建源/文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM