0

I have a rails application that has several associations. There will be a lot of content like youtube videos and images as well.

One way I can think of doing this is, by using factory girl but I cant find a way to deump the data into my development database.

It looks more like that it is for testing purposes only. However it was a close match.

I do not want to use seeds.rb as it is to be basically used for loading default data in rails app.

I plan on using faker gem as well.

I cant use migrations for such a heavy operation either/ or rather it should not be used.

Please suggest

whizcreed
  • 2,700
  • 3
  • 22
  • 35
  • 1
    I would simple write a rake task, which contains a script, where the data is generated.. you could also use factory girl or faker gem within your script..just require the necessary files. I would not think to complicated ;-).. – Matthias Jan 14 '15 at 10:50
  • Thanks for the comment @Mattherick but I am not sure how I would save the factory girl record objects to be development db? It would be great help if you could point me to a docs page.. And maybe even post it as answer that I can accept. – whizcreed Jan 14 '15 at 12:33

1 Answers1

0

Modify your Gemfile and add the factory_girls_rails gem to it. Pay attention and add it also to your development group:

group :development, :test do
  gem 'factory_girl_rails'
end

Install the bundle

bundle install

Generate a new rake task for example in lib/tasks/data.rake

 namespace :data do

  desc "generate development data"
  task :generate => :environment do
    100.times do
      FactoryGirl.create(:article) # assumed you have an articles factory
    end

    100.times do
      FactoryGirl.create(:your_model)
    end
  end

end

Call your rake task in your console:

bundle exec rake data:generate

And the data will be saved to your development database - or also to production or staging or whatever if you pass the environment..

Matthias
  • 4,355
  • 2
  • 25
  • 34