拆分seeds.rb文件 [英] Split seeds.rb file
问题描述
我的 seeds.rb
文件变得非常大.重构文件中数据的最佳方法是什么?
My seeds.rb
file is getting very large. What is the best way to refactor the data in the file?
我可以将数据放入各种文件中,并在seeds.rb
文件中require
它们吗?
Can I put the data into various files and require
them in the seeds.rb
file?
推荐答案
既然你的 seeds.rb
文件是 Ruby,那么你可以在其中做任何你可以在 Ruby 中做的事情.像 routes.rb
和 Gemfile
一样,如果需要,您可以变得非常有创意.
Since your seeds.rb
file is Ruby, then you can do anything in it you can do in Ruby. Like routes.rb
and Gemfile
you can get quite creative if required.
请确保您不要做任何疯狂的事情,以至于实际上需要进行一些调试.只要你保持你的行为清晰,就不应该有任何混乱.也就是说,不要使用在某些其他文件中定义的自定义帮助程序方法,这些文件可能会出现故障并且必须手动追踪.在做这样的事情时,最好坚持最简单的解决方案.
Just be sure that you don't do anything so crazy it would actually require some debugging. As long as you keep your actions clear, there should be no confusion. That is, don't use custom helper methods that are defined in some other file that could malfunction and would have to be tracked down by hand. It's probably best to stick to the simplest solution when doing things like this.
这篇关于拆分seeds.rb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!