Seeding and Ports

Seed Files

Make sure you have data in your local app

$ rake db:seed:dump MODEL=Activity
$ rake db:seed:dump

For a specific model:

For all models:

gem 'seed_dump'

Working collaboratively on GitHub? Use a seed file to share data!

$ bundle install

seeds.rb

You now have a seed file in your db folder. It contains all the data that was in your local db.

Artist.create!([
  {name: "Matt & Kim", avatar_file_name: "MattKim2012FallTour.jpg", avatar_content_type: "image/jpeg", avatar_file_size: 104360, avatar_updated_at: "2015-02-11 13:20:32"},
  {name: "Michael Bolton", avatar_file_name: "mb.jpg", avatar_content_type: "image/jpeg", avatar_file_size: 15160, avatar_updated_at: "2015-02-11 14:20:08"},
  {name: "LL Cool J", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil},
  {name: "Madonna", avatar_file_name: "Madonna-True-Blue.jpg", avatar_content_type: "image/jpeg", avatar_file_size: 13217, avatar_updated_at: "2015-02-11 14:43:17"}
])
Song.create!([
  {name: "Daylight", artist_id: 1, rating: 7},
  {name: "Camera", artist_id: 1, rating: 6},
  {name: "Said I Loved You", artist_id: 4, rating: 10},
  {name: "When A Man Loves A Woman", artist_id: 4, rating: 2},
  {name: "Like a Virgin", artist_id: 12, rating: 7},
  {name: "Like a Prayer", artist_id: 12, rating: 6}
])

Now What?

Push to GitHub!

Then have your teammates clone your repo on their machine. You can try mine.

 

$ git clone https://github.com/jpanaia/top_5.git
$ cd top_5

Seed your db

Then they'll need to run the following rake commands to populate or seed their database with your data.

$ rake db:seed
$ rake db:migrate

Rake Commands

Delete a database

$ rake db:drop 
$ rake db:rollback 

Rollback most recent migration

$ rake db:seed 

Runs the db/seed.rb file

Other ports

Run a server on a different port

$ rails s -p 3001

Rails Goodies

By tts-jaime

Rails Goodies

  • 976