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

Feb 7, 2011

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 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 includes sass (there's no sass gem). 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.

Our goal this week is to create an application that leverages the framework as much as possible. After reviewing your approach to solving certain features, I'll provide you feedback on whether you nailed it, leveraging the framework, or if you overlooked an easier way to implement a feature.