-
Get a monthly update on best practices for delivering successful software.
Controllers are an obvious point to find repeated behavior in an application. Identical methods across many controllers are a very common problem: consider comments, for example, where you might encounter an add_comment and remove_comment in every controller. Or think of all the controllers that render the same actions in the same way. Maybe they implement very basic CRUD functionality but have very complicated AJAXy tricks. You find yourself typing in those tricks over and over again on every controller. Let's fix that! By using a few neat techniques, we can significantly DRY up our controllers and end up with code that's not only very reusable, but very easily changeable to effect significant alterations in our application.
Continue reading »
Topics: rails controllers, rails polymorphic, Ruby on Rails