我在Rails的2.3.5,我有这样的问题:为什么Rails before_filter在控制器被子类化时调用两次?
class BaseController < ApplicationController
before_filter :foo, :only => [:index]
end
class ChildController < BaseController
before_filter :foo, :only => [:index, :show, :other, :actions]
end
的问题是,在ChildController的:过滤器之前FOO被调用两次。
我已经尝试了一些解决此问题的解决方法。如果我不在孩子中包含:index
操作,它将永远不会被请求执行该操作。
的解决方案,我发现的作品,但我认为这是非常非常难看
skip_before_filter :foo
before_filter :foo, :only => [:index, :show, :other, :actions]
有没有更好的办法来解决这个问题呢?