Rails before_filter on subclasses beeing called twice
Posted
by rubenfonseca
on Stack Overflow
See other posts from Stack Overflow
or by rubenfonseca
Published on 2010-05-24T16:10:55Z
Indexed on
2010/05/24
16:31 UTC
Read the original article
Hit count: 192
Hi! I'm at Rails 2.3.5 and I have this problem:
class BaseController < ApplicationController
before_filter :foo, :only => [:index]
end
class ChildController < BaseController
before_filter :foo, :only => [:index, :show, :other, :actions]
end
The problem is that on ChildController, the :foo before filter gets called twice.
I've tried a number of workarounds around this problem. If I don't include the :index action on the child, it never gets called for that action.
The solution I found works, but is very very ugly
skip_before_filter :foo
before_filter :foo, :only => [:index, :show, :other, :actions]
Is there a better way to solve this problem? Thanks
© Stack Overflow or respective owner