Require files no seeds.rb

0

I need to organize my seeds.rb file, so I created a namespace where I will add my classes ex:

module Seeds
 class Apple
   def self.run
     puts 'teste'
   end
 end
end
Seeds::Apple.run

This works perfectly, but I need to separate my classes into separate files similar to the structure below:

db
  seeds
    Apple.rb
  seeds.rb

and no seeds.rb:

require 'db/seeds/Apple'
Seeds::Apple.run

and it returns an error that can not load the file, what could it be?

    
asked by anonymous 08.04.2015 / 18:43

2 answers

0

Use the gem link , it "turbines" the operation of the seeds.

    
08.04.2015 / 22:19
1
  

Use the code below to include all files in the seeds folder

     

Use Rails.root to get the full path to file.

# Include ruby files
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |filename|
  puts load(filename) if File.exist?(filename)
end
Seeds::Apple.run
    
08.04.2015 / 18:53