Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
caches_action :if method still called when filter chain is halted #1918
class ProjectsController < ApplicationController before_filter :cancel_action, :only => [:index] caches_action :index, :if => :explode def index render :text => "Projects Index" end def new render :text => "Project New" end def explode logger.info "Calling caches_action if" raise "Explosion since we weren't expecting to run this method" end def cancel_action logger.info "Trying to cancel" redirect_to :action => :new end end
A simple (contrived) example. If you try to access the ProjectsController#index method it halts the filter chain by redirecting to the new action, BUT Rails still runs the if method for caches_action even though the response was generated by the before_filter so there is no point trying to cache it.
Confirmed in 3.0.9 and master.
caches_action is a simple around_filter.
Therefore it means all around_filters get executed even though a previous before_filter has halted the chain.