Join Kevin Skoglund for an in-depth discussion in this video How to use the exercise files, part of Ruby on Rails: Get More From ActiveRecord.
- [Instructor] If you're a premium member of the Lynda.com training library, you will have access to the exercise files that are used throughout this title. The exercise files for this title are arranged by chapter and by movie. You can find the exercise files that correspond the movie that you're watching by first looking for the chapter number and then the movie number. In order to make use of the exercise files, you'll want to first make sure that you have Ruby, Ruby Gems, Ruby on Rails, and MySQL installed. Once everything's installed, then you can copy the folder of exercise files into your web directory or another convenient location.
It's always a good idea to make a copy so you still have the original to refer back to if you make changes. On my MAC, I'm going to put them into my Sites directory, which is inside my user directory. I will option+drag the files, so that it creates a new copy. Now your files will be the same as mine at the start of the movie and you'll be able to work right along with me. We will also be incorporating a database into our project and for the exercise files to work, your database needs to match what the files expect. After moving the files to the correct location and making sure that you have a database created, go to your command line and navigate to the root of your Rails application.
From there, you can run rails, otl:import, to run an import script, which will import the data that the code needs and that I'll be using in the movie. Importing can also be useful if you do a lot of experimenting on your own but then want to get your data back in sync with mine. Let's open this window just a little bit wider so we can see what's here. You can see that it prompts you here, it tells you we got an import task. You'll see that it tells you how you can create the database if you haven't done that before. You can set up all the user privileges. And then, it gives us prompts down here for whether we want to proceed or not.
I'm going to type yes, we want to proceed. And then we can choose the default settings by just hitting return. What should our database host name be? It's local host because we're running on our local computer. The database name, demo project development is the default name and what you probably are using. The default database user name is rails_user. Type something different if you want to have a different name. But if you just type return, it'll keep the default. And then the import file path will be in the DB directory of the project and the file is called demo project development.sql.
That file is already included for you. So we just hit return. It says "please enter the correct MySQL password". This is the password that we created before. In the course I just demonstrate using simple password as the password but that's not very secure and you should pick your own. Once it's done, it'll say import complete. If your a monthly or annual subscriber to Lynda.com, you won't have the exercise files that accompany this tutorial but you can follow along with me. Everything that's in the exercise files we will create during the tutorials, so as long as you can continue to work along with me, your files will exactly mirror what's in the exercise files.
Remember that you can pause the video or rewind if you need more time to copy something down.
- Migrating databases
- Creating, updating, and deleting records
- Tracking changes to objects and attributes
- Writing queries
- Delegating attributes
- Working with associations