我想知道是否有方法從現有數據中自動生成seed_fu文件?現有數據庫中的seed_fu
我正在使用Rails 3和MySql。
seed_fu插件:https://github.com/mbleigh/seed-fu
我想知道是否有方法從現有數據中自動生成seed_fu文件?現有數據庫中的seed_fu
我正在使用Rails 3和MySql。
seed_fu插件:https://github.com/mbleigh/seed-fu
最佳解答不再起作用:
SeedFu::Writer.write('path/to/file.rb',{ class_name: 'Person', constraints: [:first_name, :last_name]}) do |writer|
Person.all.each do |person|
writer << person.as_json
end
end
種子福作家使用< <(種子)的方法將種子數據引入到塊中,回答最高會導致塊丟失異常。
還需要通過類名和限制內{}選項鍵,以便作家EM需要作爲選項參數
編輯
根據Rails Seed-Fu Writer why seed got commented out? @Albert Netymk評論更新了答案。
您應該使用SeedFu::Writer
生成seed_fu文件,請參閱http://rubydoc.info/github/mbleigh/seed-fu/master/SeedFu/Writer爲例。
已更新答案以反映當前的seed_fu版本,正如推薦的[這裏](http://meta.stackexchange.com/questions/11705/how-to-deal-with-obsolete-answers) – Petr
上面的代碼片段會導致註釋輸出。看到這[SO](http://stackoverflow.com/questions/24230462/rails-seed-fu-writer-why-seed-got-commented-out)瞭解更多信息。 –