Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要创建一个从文件系统源导入数据的脚本。我怎么做?
我已经尝试创建一个 rake 任务,但没有加载模型。如何让整个 Rails 环境融入我的任务?
desc 'Do stuff with models' task :do_stuff => :environment do 1000.times.each do |i| Model.create :name => "model number #{i}" end end
您声明:environment为 rake 任务的依赖项。这会在运行之前加载 rails 和所有应用程序代码。
:environment