Improved Seeds Folder Structure

Sets up environment specific seeds folders
Icons/chart bar
Used 26 times
Created by
D Dale Zak

Usage
Organize your seeds files into environment folders and execute them in alphanumeric order.

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/xGqsmL"
Template Source

Review the code before running this template on your machine.

file 'db/seeds.rb', <<-CODE
Dir[Rails.root.join('db', 'seeds', '*.rb')].sort.each do |seed|
  load seed
end
Dir[Rails.root.join('db', 'seeds', Rails.env, '*.rb')].sort.each do |seed|
  load seed
end
CODE

file 'db/seeds/01_settings.rb', <<-CODE
# all environments
CODE

file 'db/seeds/development/01_users.rb', <<-CODE
# development only
CODE

file 'db/seeds/production/01_users.rb', <<-CODE
# production only
CODE
Comments

Sign up or Login to leave a comment.