2016-11-11 67 views

回答

7

lib/tasks/處創建一個文件。給新文件命名爲main_seed_file.rake。將以下代碼粘貼到main_seed_file.rake

desc "Run all files in db/seeds directory" 
namespace :db do 
    task seeds: :environment do 
    Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |filename| 
     puts "seeding - #{filename}" 
     load(filename) 
    end 
    end 
end 

現在執行這個rake db:seeds

乾杯!

相關問題