## db/seeds.rb ['all', Rails.env].each do |seed| seed_file = Rails.root.join('db', 'seeds', "#{seed}.rb") if File.exists?(seed_file) puts "*** Loading #{seed} seed data" require seed_file end seed_dir = Rails.root.join('db', 'seeds', seed) if File.directory?(seed_dir) Dir[File.join(seed_dir, "*.rb")].each do |file| puts "*** Loading #{seed} seed data from #{file}" require file end end end ############################## ## Example of folder structure ## db/seeds/all.rb # Seeds for all environments ## db/seeds/development.rb # Seeds only for the "development" environment. ## db/seeds/test.rb # Seeds only for the "test" environment. ## db/seeds/production.rb # Seeds only for the "production" environment. ## db/seeds/development/users.rb # Seeds only for the "development" environment. # ... seed users ... ## db/seeds/development/articles.rb # Seeds only for the "development" environment. # ... seed articles ... ## db/seeds/production/users.rb # Seeds only for the "production" environment. # ... seed users ... ## db/seeds/production/articles.rb # Seeds only for the "production" environment. # ... seed articles ... ######################################### ## Recommended shared seeds files pattern ## db/seeds/shared/dev_users.rb # Seeds for any environment but must be manually required # ... create users only for some environments. ## db/seeds/development.rb # Seeds only for the "development" environment. require_relative "shared/dev_users.rb" ## db/seeds/staging.rb # Seeds only for the "staging" environment. require_relative "shared/dev_users.rb"