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

Closed
rywall opened this Issue Jun 30, 2011 · 3 comments

Comments

Projects
None yet
4 participants
@rywall
Contributor

rywall commented Jun 30, 2011

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

This comment has been minimized.

Show comment
Hide comment
@dmathieu

dmathieu Jul 1, 2011

Contributor

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.

Contributor

dmathieu commented Jul 1, 2011

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

This comment has been minimized.

Show comment
Hide comment
@jonkessler

jonkessler Apr 25, 2012

Contributor

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

Contributor

jonkessler commented Apr 25, 2012

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

@tenderlove

This comment has been minimized.

Show comment
Hide comment
@tenderlove

tenderlove Jun 30, 2012

Member

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

Member

tenderlove commented Jun 30, 2012

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

@tenderlove tenderlove closed this Jun 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment