简体   繁体   中英

Rails: NoMethodError: undefined method `load_documents' for Psych:Module

I've been using the yaml_db gem for a long time to dump the database to yaml and then reload it later if needed. On a fresh project, though, on rake db:load I got the error message:

NoMethodError: undefined method `load_documents' for Psych:Module
Did you mean?  load_stream
/Users/user/.rvm/gems/ruby-2.5.0/gems/yaml_db-0.6.0/lib/yaml_db.rb:61:in `load_documents'

I am submitting the solution I finally came up with as an answer, but I'm not really happy with it. If anyone has a better solution or a suggestion of something better than the yaml_db gem for dumping and reloading the database, I'd be happy to listen.

I'm running Rails 5.1.4 on Ruby 2.5.0

The solution I came up with was to put the 'psych' gem in my Gemfile before yaml_db and set it to an earlier release:

gem 'psych', '~> 2.2.1'
gem 'yaml_db'

This issue is caused by load_documents being deprecated in Psych and finally removed in ruby 2.5. There's an open PR on yaml_db that fixes this issue, so hopefully future versions will not require you to use this work-around.

Your current solution is probably the easiest for now (short of downgrading your ruby version, which is probably a worse idea).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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