Jeremy Durham

Ruby, Rails, and everything in between.

  • BlogThoughts
  • AboutAbout the Author
  • ContactGet in touch

March 12, 2010 09:22
Posted by Jeremy Durham

Simple rake task to allow multiple seeds

This will allow you to do rake db:seed:x where “x” is a file in the db/seeds directory:

namespace :db do
  namespace :seed do
    Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |seed_file|
      task_name = File.basename(seed_file, '.rb').intern    
      desc "Load the seed data from db/seeds/#{task_name}.rb"
      task task_name => :environment do
        load(seed_file) if File.exist?(seed_file)
      end
    end
  end
end

No Comments

Posted Under Programming

0 Comments

Leave a comment

* = Required
  • Posts
  • Twitter
  • Flickr
 

Brand loyalty: wh...

Technology

 

DNS-321 + OpenVPN...

Technology

 

There is no Holy ...

Technology

Categories

  • Technology
  • Programming
  • Family
  • Travel

This site is using the Handgloves WordPress Theme
Designed & Developed by George Wiscombe

Subscribe via RSS