Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Back in Rails 1.0 the filter chain didn't used to get cached like this and so wouldn't have been a problem.</p> <p>The reason the filter chain became cached was for performance. There's little reason not to cache it. From searching around for other people wanting it to be dynamic I found only one post. So it looks like there is rarely any need for the filter chain to be dynamic or reloadable after the app has started unless you get a case like this.</p> <p>Bearing this in mind, I think a method like FilterChain.reload would be a good way to keep the performance gains. </p> <p>In Spree FilterChain.reload could be called after loading the extensions. I prefer this to the solution I suggested in an earlier comment (patching before_filter) as I think its got a better shot of being useful to Rails core.</p> <pre><code>FilterChain.class_eval do # Reloads all filter chains on all controllers, working from the ApplicationController down # through the class hierarchy. e.g. Spree::BaseController would get its filter chain reloaded # before its subclasses like ProductsController. We do this as ProductsController's filter chain # relies on a copy of the Spree::BaseController filter chain. def self.reload # ApplicationController.filter_chain does not need reloading, it will be the only correct # filter chain for sure as it is not inherited from a superclass. reload_child_filter_chains(ApplicationController) end def self.reload_child_filter_chains(controller_class) controller_class.immediate_subclasses.each do |controller_child| # Reload filter chain on each controller who's immediate parent is the controller_class controller_child.filter_chain.merge_filter_chain(controller_class.filter_chain) # Reload the children of controller_child reload_child_filter_chains(controller_child) end end # New instance method on FilterChain to merges the given parent chain into itself. def merge_filter_chain(parent_chain) # Compare self and parent_chain and insert any parent_chain filters that # are missing from self. You may need special handling for # Filters that were marked for skipping or with :only, etc. conditions. ... end end </code></pre> <p>Taken from comments here:</p> <p><a href="http://railsdog.lighthouseapp.com/projects/31096-spree/tickets/653-specifying-filters-in-extensions-can-create-filter-chains-missing-filters" rel="nofollow noreferrer">Spree issue 653 Specifying filters in extensions can create filter chains missing filters</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload