Not sure if this is a bug, or what the correct behaviour should be.
Suppose that we have a parent and an inherited controller:
class TestController < ApplicationController
def filter
logger.debug "filter"
end
before_filter :filter, :only => [ :t1 ]
def t1
logger.debug "TestController t1"
render :text => 't1'
end
end
class TestChildController < TestController
before_filter :filter, :only => [ :t3 ] # oops what should this do?
def t3
logger.debug "TestChildController t3"
render :text => "t3"
end
end
The idea here is that the child controller might want to reuse the
filter for its new 't3' action.
What happens though is rather unexpected:
Processing TestChildController#t1 (for 127.0.0.1 at 2007-08-06
20:09:13) [GET]
Session ID: 082b6fa688bac1b0b70baa770b5754ba
Parameters: {"action"=>"t1", "controller"=>"test_child"}
TestController t1 <<<<<<<<<<<<<<<< filter not called
Completed in 0.00010 (10000 reqs/sec) | Rendering: 0.00000 (0%) | DB:
0.00000 (0%) | 200 OK [http://localhost/test_child/t1]
Processing TestChildController#t3 (for 127.0.0.1 at 2007-08-06
20:09:21) [GET]
Session ID: 082b6fa688bac1b0b70baa770b5754ba
Parameters: {"action"=>"t3", "controller"=>"test_child"}
filter
filter <<<<<<<<<<<<<<<< why called twice?
TestChildController t3
Completed in 0.00010 (10000 reqs/sec) | Rendering: 0.00000 (0%) | DB:
0.00000 (0%) | 200 OK [http://localhost/test_child/t3]
One would expect that either the new :only overrides the previous one
and only t3 invokes the filter (sensical but not convenient) or the
new :only just adds the filter to t3 and keeps the filter on t1. Or is
using :only here inherently bad?
Thanks!
Jaime Cham