![](/img/trans.png)
[英]Ruby undefined method `[]' for nil:NilClass (NoMethodError) error
[英]STORYBLOK, RUBY: undefined method `[]' for nil:NilClass (NoMethodError)
我不太了解RUBY ,只是觉得你们可能会帮助我。 我在构建服务时使用 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)
下面的代码来自_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
下面的代码来自_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
附加信息:
我实际上已经找到了解决方案,所以出现此错误是因为我在 Storyblok 的 Block Library 中创建了一个页面模板,然后在终端中触发了bundle exec jekyll serve
命令,而没有在我的项目目录中创建页面模板源/文件。
所以我在块库中创建了一个about_us
块(内容类型),然后当我在没有先在_layouts
文件夹中创建about_us.html
的情况下启动bundle exec jekyll serve
jekyll serve 时,它会触发错误。
解决方案;
如果您在块库中创建了块(内容类型),请确保首先在_layouts
文件夹中创建源/文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.