[英]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.