Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

caches_action :if method still called when filter chain is halted #1918

Closed
rywall opened this Issue · 3 comments

4 participants

@rywall
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.

@dmathieu
Collaborator

caches_action is a simple around_filter.
See https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/caching/actions.rb#L100

Therefore it means all around_filters get executed even though a previous before_filter has halted the chain.

@jonkessler

@rywall Is this still an issue? If not, please close it. Thanks.

@tenderlove
Owner

Closing due to no activity. If this is still an issue, please comment and I'll reopen. Thanks!

@tenderlove tenderlove closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.