RailsCasts Pro episodes are now free!

Learn more or hide this

Applied Filters: Active Record x
Model Caching (revised)
Episode #115May 13, 2013426 comments

Model Caching (revised)

Caching at a low level is a great option when the view is too dynamic to cache and you need something flexible that can work anywhere in the application. Here I show a variety of ways to use Rails.cache with Active Record. (12 minutes)
Eager Loading (revised)
Episode #22Mar 20, 2013223 comments

Eager Loading (revised)

One way to improve performance is to reduce the number of database queries through eager loading. Here I demonstrate this and compare the difference between the "includes" and "joins" methods. (7 minutes)
Public Activity
Episode #406Feb 13, 2013155 comments

Public Activity

Learn how to easily add a user activity feed using the public_activity gem. Here I show both the default setup using model callbacks and a manual way to trigger activities. (10 minutes)
Model Name in URL (revised)
Episode #63Dec 16, 201285 comments

Model Name in URL (revised)

A model's ID in the URL is not very helpful to the user. Consider adding the name which can also improve SEO. Learn how to override to_param, add a slug attribute, and make a catch all route for deep nesting. (9 minutes)
Tree-Based Navigation (revised)
Episode #162Dec 01, 201293 comments

Tree-Based Navigation (revised)

If your Rails app is content-heavy, consider organizing it in a tree menu structure. Here I show how to add top-level tabs, nested links in a side bar, and breadcrumbs to go up the hierarchy. (10 minutes)
STI and Polymorphic Associations
Episode #394Nov 25, 201281 comments

STI and Polymorphic Associations

Single Table Inheritance (STI) can help organize branching logic into separate classes, but a polymorphic association may be a better fit if there are unique database columns. (14 minutes)
A Tour of State Machines
Episode #392Nov 17, 201293 comments

A Tour of State Machines

Here I show how three popular state machine gems can be used to clean up a list of boolean/datetime fields. I also show a custom solution which keeps track of the history of events. (12 minutes)
Site-Wide Announcements (revised)
Episode #103Nov 12, 201295 comments

Site-Wide Announcements (revised)

Here I show how to add an announcement message at the top of every page in the application and allow the user to permanently hide it. This is all done test-first and even includes testing the JavaScript behavior. (11 minutes)
Multitenancy with PostgreSQL
Episode #389Oct 27, 2012112 comments

Multitenancy with PostgreSQL

PostgreSQL Schemas can help create a multi-tenant app by keeping data separate at the database layer. Integrating with migrations can be tricky though, so watch this episode for the full details. (11 minutes)
Multitenancy with Scopes
Episode #388Oct 20, 2012120 comments

Multitenancy with Scopes

A multi-tenant application can be difficult to implement because the data for each tenant must be completely separate. Here I show how to do this using subdomains and default scopes in Active Record. (12 minutes)