Renaming *_filter to *_action [Rails 4 Countdown to 2013]

Posted on

This post is part of a series of 31 Rails 4 articles being released each day in December 2012.

Yesterday, David Heinemeier Hansson committed a change to Action Pack that renamed all controller *filter callback methods to *action.

By suffixing _filter to the action callback methods, there was a misconception by some developers that these action callbacks could only be used for halting or transforming the response.

The callbacks were always intended to abstract common instance variable declarations for views and could also be used to give intention revealing names to common controller code.

Here is an example of an action filter setting an instance variable:

class ArticlesController < ApplicationController
  before_action :set_article, except: [:index, :new, :create]



  def set_article
    @article = Article.find(params[:id])

Upgrade Path

All existing *filter methods will still work with no deprecation warnings. Thus, to upgrade to Rails 4, you will not need to make any immediate changes. However, I would recommend doing a quick search and replace of *filter calls to *_action to future proof your code.


This post is by Kevin Faustino. Kevin is the Chief Craftsman of Remarkable Labs and also the founder of the Toronto Ruby Brigade.


comments powered by Disqus