Bummer! That course has been retired.

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Query Interface Finding Control

Could we get a copy of the database that included all of these extra records?

Code and info being added between videos has made this course pretty tricky. In this case, a bunch of records were added to make querying the database more meaningful.

I saw that one could use faker to create some fake entries, but I wonder if perhaps treehouse could get Hampton Catlin 's file instead.

Any other ideas for this?

Thanks!

2 Answers

Gavin Ralston
Gavin Ralston
28,770 Points

From the results I got, he used faker to generate them.

There's a blip on this particular video that shows the migration he whipped up to add the extra fields around 7 minutes in (The Ham named his migration CustomerInformatoin, lulz) , when he's switching windows to do something else. It matches the one I made to add them on my own:

class AddFieldsToAccounts < ActiveRecord::Migration
  def change
    add_column :accounts, :city, :string
    add_column :accounts, :zipcode, :integer
    add_column :accounts, :state, :string
    add_column :accounts, :employees, :integer
  end
end

then

rake db:migrate

If you've been following to this point, it'll go off without a hitch. You could also build the migration with rails generate if you'd prefer.

Then update the Gemfile

gem 'faker', '~>1.4.3', group: :development

Then at the command line:

bundle install

To make my data match his, I used the following code in my db > seeds.rb file

800.times do |n|
    a = Account.new
    a.name =  Faker::Company.name + " " + Faker::Company.suffix
    a.email =  Faker::Internet.email 
    a.city = Faker::Address.city 
    a.zipcode  = Faker::Address.zip_code
    a.state = Faker::Address.state_abbr
    a.about =  Faker::Company.catch_phrase
    a.type = 'Customer'
    a.employees = (rand * 90).to_i

    a.save
end

Which is a slight modification of the faker options shown in another post so I got state abbreviations and full city names (and I'm sure there's a slicker way to concat the company names)

then back to command line to seed that thing, run this as many times as you want:

rake db:seed 

Should be up and running and looking just like the data in the video.

Hope that helps a bit.

Lisa Pollack
Lisa Pollack
4,603 Points

THAT worked beautifully! Thank you, Gavin!

Adam Butterworth
Adam Butterworth
12,621 Points

Love your work man... worked a treat :-) Thanks Gavin

I've been meaning to tell you that I ended up figuring faker eventually! At the time I posted this, though, there was a lot of darnit! happening. :grinning:

great response to help other folks out!

Gabriele Rossi
Gabriele Rossi
5,887 Points

This is great, thank you! :)

Thank you very much!

Great work - thank you for this!! :-))

Steve.

That was super helpful and it forced me to learn how to edit the gemfile though I ended up doing it this way. I'm assuming it's because I'm on Rails 5.

group :development, :test do
  gem 'faker'
end
Zachary Betz
Zachary Betz
10,413 Points

Thanks Gavin! Worked like a charm.

Javier Mera
Javier Mera
16,472 Points

Thanks for the mega post!