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 trialJim Withington
12,025 PointsCould 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
28,770 PointsFrom 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.
Javier Mera
16,472 PointsThanks for the mega post!
Lisa Pollack
4,603 PointsLisa Pollack
4,603 PointsTHAT worked beautifully! Thank you, Gavin!
Adam Butterworth
12,621 PointsAdam Butterworth
12,621 PointsLove your work man... worked a treat :-) Thanks Gavin
Jim Withington
12,025 PointsJim Withington
12,025 PointsI'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.
great response to help other folks out!
Gabriele Rossi
5,887 PointsGabriele Rossi
5,887 PointsThis is great, thank you! :)
Andrew Gay
20,893 PointsAndrew Gay
20,893 PointsThank you very much!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsGreat work - thank you for this!! :-))
Steve.
John Simoneau
Courses Plus Student 8,105 PointsJohn Simoneau
Courses Plus Student 8,105 PointsAwesome! Thanks!
Jeremy Flanagan
12,454 PointsJeremy Flanagan
12,454 PointsThat 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.
Zachary Betz
10,413 PointsZachary Betz
10,413 PointsThanks Gavin! Worked like a charm.