Skip to content

Instantly share code, notes, and snippets.

@dyanagi
Last active September 25, 2019 05:09
Show Gist options
  • Save dyanagi/0259af6f4ed5da4b76f0ad18581f725e to your computer and use it in GitHub Desktop.
Save dyanagi/0259af6f4ed5da4b76f0ad18581f725e to your computer and use it in GitHub Desktop.
A Rake task file that populates example data for development in Ruby on Rails
# lib/tasks/dev.rake
if Rails.env.development?
namespace :dev do
desc 'Drop, create, load schema, migrate, seed, and populate sample data'
task prepare: ['db:drop', 'db:create', 'db:schema:load',
'db:migrate', 'db:seed', :populate_sample_data] do
puts 'Ready to go!'
end
desc 'Populates the database with sample data'
task populate_sample_data: :environment do
user = User.new email: 'test@example.com', password: 'password'
user.skip_confirmation!
user.save!
# Add more sample data
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment