问题描述
使用Rails的2/3,有可能和易于使用的一些插件(请参阅Best方法将数据库表导出到YAML文件?)。
With Rails 2/3 it was possible and easy to export (dump) a database to YAML using one of a few plugins (see Best way to export a database table to a YAML file?).
然而,这些插件似乎是使用Rails 4.兼容还会出现一个简单的方法来做到这一点?
However, none of these plugins seem to be compatible with Rails 4. Is there still an easy way to do this?
推荐答案
在这个问题挂钩后指示的方法仍然有效,但code不是了一个插件:这是yaml_db宝石。
The method indicated in the post linked in the question is still valid, but the code is not anymore a plugin: it's the yaml_db gem.
这个仓库是 https://github.com/yamldb/yaml_db
要转储数据库,创业板添加到Gemfile中,问题
To dump the db, add the gem to the Gemfile, issue
bundle update
然后问题:
rake db:data:dump
转储文件是:
the dump file is:
db/data.yml
如果像我一样,你打错误
If, like me, you hit the error
undefined method `[]=' for #<ActiveRecord::Result:0x007ff34c76d508>
也可以是固定按照本票的指示:
it can be fixed by following the instructions given in this ticket:
https://github.com/ludicast/yaml_db/pull/45
所有你应该做的就是添加
All you should have to do is add
gem 'yaml_db', github: 'jetthoughts/yaml_db', ref: 'fb4b6bd7e12de3cffa93e0a298a1e5253d7e92ba'
到Gemfile文件
to the Gemfile
这篇关于轨道4:导出数据库YAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!