Unit 5: ActiveRecord Associations, Common Gems/Plugins, HAML and SASS

Feb 20, 2012

Objectives

Learn how to think at the database- and object- level with ActiveRecord associations.

Learn about common gems (will_paginate) and better declarative interface tools (haml, sass).

Recap / Prerequisites

Whew! You should have completed the basic Articl.es application and have viewed the Project 4 solution screencast.

Common Gems / Plugins

First, take a brief look at the changes you have to implement this week. There are certain gems / plugins that all Rails developers should be very familiar with. The first is will_paginate which makes model pagination very easy. The other is paperclip which allows you to "attach" files, such as pictures, to your models.

Next, you'll want to learn about haml and sass. Note that the haml gem and sass gems are now separate. The haml gem includes utilities for converting markup to haml, css to sass, etc. so don't convert them by hand. Use the tools first, then massage the generated results yourself, manually.

Here are some relevant screencasts and references for this week:

Railscast 2: Dynamic find_by methods you should know about this!

Railscast 6: Symbol to_proc (useful for your author attribute-to-model migration)

Railscast 7: Layouts

Railscast 10, Railscast 11, Railscast 12 on refactoring views.

Railscast 55: Cleaning up the View another good example on keeping views slim and declarative.

Railscast 22: Eager Loading try using this in your Article and Author views, to reduce the database queries!

Railscast 51: will_paginate be sure to read the doco on github as the API has changed.

Railscast 134: Paperclip which will show you how to make file attachments easy-peasy.

Homework These Two Weeks

This unit is two weeks long. Our readings and project work are entirely focused on getting you more familiar with the Rails framework and iteratively improving a Web app from a set of changing requirements.

  1. Participate in answering (and asking) questions on Piazza.
  2. Watch the Project 4 solution screencast.
  3. Watch all of the Railscasts listed above.
  4. Read Agile Web Development with Rails chapters 18, 19 and 23 (Finding your way around, ActiveRecord, and Migrations).
  5. Complete Project 5, due March 5.