RailsCasts Pro episodes are now free!

Learn more or hide this

Applied Filters: Refactoring x
Form Objects
Episode #416 – Jun 03, 2013 – 335 comments

Form Objects

Models have a tendency to become a complex mess as an application grows. In this episode you will learn a couple of techniques to extract form-behavior out into its own class. (18 minutes)
Service Objects
Episode #398 – Dec 18, 2012 – 114 comments

Service Objects

Models can quickly become a grab-bag of unrelated methods if behavior is constantly being pushed from the controller. Here I show how to refactor this using Concerns and Service Objects. (12 minutes)
STI and Polymorphic Associations
Episode #394 – Nov 25, 2012 – 81 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)
Hacking with Arel
Episode #355 – May 30, 2012 – 70 comments

Hacking with Arel

Here I show a variety of ways to rewrite a long SQL query using only Active Record and Arel. This includes generating scopes dynamically, adding an "or" operator, and adding a powerful "match" method. (15 minutes)
Form Builders
Episode #311 – Dec 26, 2011 – 42 comments

Form Builders

Forms often follow a similar pattern with a lot of repetition. Learn how to clean up form views and remove duplication with the help of form builders. (12 minutes)
Presenters from Scratch
Episode #287 – Oct 03, 2011 – 122 comments

Presenters from Scratch

Clean up complex view logic with the help of presenters, and doing this from scratch gives you a lot of flexibility. Here I show not only how to create presenters, but how to test them using Test Unit and RSpec. (14 minutes)
Draper
Episode #286 – Oct 03, 2011 – 71 comments

Draper

Clean up complex view logic using Draper. This gem provides decorators (much like presenters) which bundles view logic in an object oriented fashion. In this episode I do a step-by-step refactoring of a complex template into a decorator. (12 minutes)
How I Test
Episode #275 – Jul 18, 2011 – 137 comments

How I Test

Here I show how I would add tests to the password reset feature created in the previous episode. I use RSpec, Capybara, Factory Girl, and Guard to make request, model, and mailer specs. (15 minutes)
Refactoring & Dynamic Delegator
Episode #212 – May 03, 2010 – 50 comments

Refactoring & Dynamic Delegator

Learn how to refactor a set of conditional Active Record queries using a Dynamic Delegator. (7 minutes)
Site Wide Announcements
Episode #103 – Apr 28, 2008 – 58 comments

Site Wide Announcements

Sometimes you need to display an administrative announcement to every page on the site and give the users the ability to hide the announcement. See how in this episode. (13 minutes)