Lab Exercises

These are recommended exercises you can do inside the Rails command-line console. But first, you will need to set up a model and scaffold of your choosing.

You are encouraged to refer to the online ActiveRecord guide.

Exercises at the command-line console

  1. Using your model class, create a new data object
  2. Assign values to the object's properties
  3. Save the object
  4. Use find and where to retrieve objects
  5. Modify, resave and delete objects
  6. Use the find_by_property method to search for specific data objects
  7. Verify that the new data objects have been added to the database by running your application.

You may also want to use this time to start the next assignment.

Additional exercises (as time permits)

  1. Set up a git repository on github. To do this, you'll need to create an account. Then, follow this tutorial on creating a repo. However, for Step 1, instead of just making a directory (e.g. mkdir ~/Hello-World), you should create a Rails application (e.g. rails new my_app).
  2. Review advanced finding in the book (pp. 52 - 54). Use the console to execute find queries with partially matching key words.
  3. Add a new table and set up relationships between the two tables. For example, you may want to add a "comments" tables that has a many-to-one relationship to your table. Use the console to access and modify records.
  4. Add some of the customizations discussed in class last week (e.g. validations, routing from the root, virtual model attributes, conditional displays in the view).