diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-09-19 17:21:16 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-20 10:41:05 +0200 |
commit | d475de7e2573847bf4b13c291618053f30070a21 (patch) | |
tree | 7dbb9fc50009b1b9f30c97c486b238f03f270c55 /railties/lib/rails | |
parent | 0523b55ab9f823b0cb3643714e890b2c2077820e (diff) | |
download | rails-d475de7e2573847bf4b13c291618053f30070a21.tar.gz rails-d475de7e2573847bf4b13c291618053f30070a21.tar.bz2 rails-d475de7e2573847bf4b13c291618053f30070a21.zip |
Add helper for loading seed data for engine and application
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/engine.rb | 9 | ||||
-rw-r--r-- | railties/lib/rails/engine/configuration.rb | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 10df9b3a6c..8387f277c9 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -380,6 +380,15 @@ module Rails @config ||= Engine::Configuration.new(find_root_with_flag("lib")) end + # Load data from db/seeds.rb file. It can be used in to load engines' + # seeds, e.g.: + # + # Blog::Engine.load_seed + def load_seed + seed_file = config.paths.db.seeds.to_a.first + load(seed_file) if File.exist?(seed_file) + end + # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path, :before => :bootstrap_hook do _all_load_paths.reverse_each do |path| diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 3ac8911ba8..d4d87be527 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -37,6 +37,7 @@ module Rails paths.vendor.plugins "vendor/plugins" paths.db "db" paths.db.migrate "db/migrate" + paths.db.seeds "db/seeds.rb" paths end end |