jekyll/jekyll-admin

When published: false, get NoMethodError - undefined method `to_api' for nil:NilClass: upon post save

jkcchan opened this issue · 6 comments

Description:

When front matter published: false
When create/save file, error: NoMethodError - undefined method `to_api' for nil:NilClass:
The file is saved and created, however the post is not populated in the UI.
Related: #91 #426

Tell us a bit about yourself:

  • Version of JekyllAdmin I'm using <HINT: use bundle show to check>: 0.9.0
  • Version of Jekyll I'm using <HINT: use bundle show to check>: 4.0.0
  • Version of NodeJS I'm using <HINT: use node -v to check>: 10.7.0
  • Operating System <e.g. OS X, Windows>: OSX
  • Browser <e.g, Safari, Chrome>: Firefox

Steps to reproduce:

When front matter published: false
When create/save file, error: NoMethodError - undefined method `to_api' for nil:NilClass:
The file is saved and created, however the post is not populated in the UI.

I expected the following:

But got the following, instead:

Could be by design.

Other details:

Thank you for reporting this @jkcchan
This is part of a known issue with this plugin. Nevertheless, we're working on a patch to resolve similar issues.

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

zhum commented

Bug is still present.

  • bundler (2.1.2)
  • jekyll (4.1.1)
  • jekyll-admin (0.11.0)
  • sinatra (1.4.8)
  • sinatra-contrib (1.4.7)
  • node v10.19.0
    Linux Mint 20.1, Firefox.

I am also having this issue, has anyone figured out a fix?

EDIT: My issue was that I had two _posts folders, since I went ahead and made a my_collections folder to create my own collections. Everything works great now that I moved the _posts into the my_collections directory.

Regenerating: 2 file(s) changed at 2021-03-05 18:58:44
    _posts/2021-03-05-Intro-To-Gameplay-Mathematics.md
    my_collections/_posts/2021-03-05-test.md
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-3.9.0/lib/jekyll/reader.rb:42: warning: conflicting chdir during another chdir block
2021-03-05 18:58:48 - NoMethodError - undefined method `to_api' for nil:NilClass:
        C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-admin-0.11.0/lib/jekyll-admin/server/collections.rb:37:in `block (2 levels) in <class:Server>'```

Okay, it appears that I've run into the issue again and figured out that Jekyll Admin occasionally makes a new _posts folder which causes the deletion of the post, although it is only deleted from the _posts in your designated collections folder. Not sure how to fix this, but if I ever figure it out I'll post here.

@jkcchan

#!/bin/bash

# fix write file error
PATH_TO_FILE_HELPER=/usr/lib/ruby/gems/3.1.0/gems/jekyll-admin-0.11.1/lib/jekyll-admin/file_helper.rb
sed -i '25,25{s/^/#/}' $PATH_TO_FILE_HELPER
sed -i '32,32{s/^/#/}' $PATH_TO_FILE_HELPER

# fix to_api error
PATH_TO_FILE_PAGES=/usr/lib/ruby/gems/3.1.0/gems/jekyll-admin-0.11.1/lib/jekyll-admin/server/pages.rb
sed -i '28,28{s/^/#/}' $PATH_TO_FILE_PAGES
sed -i '28,28{s/^/ \
        if new? || renamed? \
          sleep(1) \
          path = {"path": write_path.split("\/").slice(4, write_path.length()).join("\/")} \
          json path \
        else \
          json written_file.to_api(:include_content => true) \
        end \
 \
/}' $PATH_TO_FILE_PAGES