Module: ActionController::Filters::ClassMethods
- Defined in:
- lib/action_controller/filters.rb
Instance Method Summary collapse
-
#after_filters ⇒ Object
Returns all the after filters for this class and all its ancestors.
-
#append_after_filter(*filters, &block) ⇒ Object
(also: #after_filter)
The passed
filters
will be appended to the array of filters that run after actions on this controller are performed. -
#append_around_filter(*filters, &block) ⇒ Object
(also: #around_filter)
If you
append_around_filter A.new, B.new
, the filter chain looks like. -
#append_before_filter(*filters, &block) ⇒ Object
(also: #before_filter)
The passed
filters
will be appended to the filter_chain and will execute before the action on this controller is performed. -
#before_filters ⇒ Object
Returns all the before filters for this class and all its ancestors.
-
#filter_chain ⇒ Object
Returns an array of Filter objects for this controller.
-
#prepend_after_filter(*filters, &block) ⇒ Object
The passed
filters
will be prepended to the array of filters that run after actions on this controller are performed. -
#prepend_around_filter(*filters, &block) ⇒ Object
If you
prepend_around_filter A.new, B.new
, the filter chain looks like:. -
#prepend_before_filter(*filters, &block) ⇒ Object
The passed
filters
will be prepended to the filter_chain and will execute before the action on this controller is performed. -
#skip_after_filter(*filters) ⇒ Object
Removes the specified filters from the
after
filter chain. -
#skip_before_filter(*filters) ⇒ Object
Removes the specified filters from the
before
filter chain. -
#skip_filter(*filters) ⇒ Object
Removes the specified filters from the filter chain.
Instance Method Details
#after_filters ⇒ Object
Returns all the after filters for this class and all its ancestors. This method returns the actual filter that was assigned in the controller to maintain existing functionality.
553 554 555 |
# File 'lib/action_controller/filters.rb', line 553 def after_filters #:nodoc: filter_chain.select(&:after?).map(&:method) end |
#append_after_filter(*filters, &block) ⇒ Object Also known as: after_filter
The passed filters
will be appended to the array of filters that run after actions on this controller are performed.
461 462 463 |
# File 'lib/action_controller/filters.rb', line 461 def append_after_filter(*filters, &block) filter_chain.append_filter_to_chain(filters, :after, &block) end |
#append_around_filter(*filters, &block) ⇒ Object Also known as: around_filter
If you append_around_filter A.new, B.new
, the filter chain looks like
B#before
A#before
# run the action
A#after
B#after
With around filters which yield to the action block, before
and after
are the code before and after the yield.
484 485 486 |
# File 'lib/action_controller/filters.rb', line 484 def append_around_filter(*filters, &block) filter_chain.append_filter_to_chain(filters, :around, &block) end |
#append_before_filter(*filters, &block) ⇒ Object Also known as: before_filter
The passed filters
will be appended to the filter_chain and will execute before the action on this controller is performed.
446 447 448 |
# File 'lib/action_controller/filters.rb', line 446 def append_before_filter(*filters, &block) filter_chain.append_filter_to_chain(filters, :before, &block) end |
#before_filters ⇒ Object
Returns all the before filters for this class and all its ancestors. This method returns the actual filter that was assigned in the controller to maintain existing functionality.
547 548 549 |
# File 'lib/action_controller/filters.rb', line 547 def before_filters #:nodoc: filter_chain.select(&:before?).map(&:method) end |
#filter_chain ⇒ Object
Returns an array of Filter objects for this controller.
536 537 538 539 540 541 542 543 |
# File 'lib/action_controller/filters.rb', line 536 def filter_chain if chain = read_inheritable_attribute('filter_chain') return chain else write_inheritable_attribute('filter_chain', FilterChain.new) return filter_chain end end |
#prepend_after_filter(*filters, &block) ⇒ Object
The passed filters
will be prepended to the array of filters that run after actions on this controller are performed.
467 468 469 |
# File 'lib/action_controller/filters.rb', line 467 def prepend_after_filter(*filters, &block) filter_chain.prepend_filter_to_chain(filters, :after, &block) end |
#prepend_around_filter(*filters, &block) ⇒ Object
If you prepend_around_filter A.new, B.new
, the filter chain looks like:
A#before
B#before
# run the action
B#after
A#after
With around filters which yield to the action block, before
and after
are the code before and after the yield.
498 499 500 |
# File 'lib/action_controller/filters.rb', line 498 def prepend_around_filter(*filters, &block) filter_chain.prepend_filter_to_chain(filters, :around, &block) end |
#prepend_before_filter(*filters, &block) ⇒ Object
The passed filters
will be prepended to the filter_chain and will execute before the action on this controller is performed.
452 453 454 |
# File 'lib/action_controller/filters.rb', line 452 def prepend_before_filter(*filters, &block) filter_chain.prepend_filter_to_chain(filters, :before, &block) end |
#skip_after_filter(*filters) ⇒ Object
Removes the specified filters from the after
filter chain. Note that this only works for skipping method-reference filters, not procs. This is especially useful for managing the chain in inheritance hierarchies where only one out of many sub-controllers need a different hierarchy.
You can control the actions to skip the filter for with the :only
and :except
options, just like when you apply the filters.
521 522 523 |
# File 'lib/action_controller/filters.rb', line 521 def skip_after_filter(*filters) filter_chain.skip_filter_in_chain(*filters, &:after?) end |
#skip_before_filter(*filters) ⇒ Object
Removes the specified filters from the before
filter chain. Note that this only works for skipping method-reference filters, not procs. This is especially useful for managing the chain in inheritance hierarchies where only one out of many sub-controllers need a different hierarchy.
You can control the actions to skip the filter for with the :only
and :except
options, just like when you apply the filters.
511 512 513 |
# File 'lib/action_controller/filters.rb', line 511 def skip_before_filter(*filters) filter_chain.skip_filter_in_chain(*filters, &:before?) end |
#skip_filter(*filters) ⇒ Object
Removes the specified filters from the filter chain. This only works for method reference (symbol) filters, not procs. This method is different from skip_after_filter and skip_before_filter in that it will match any before, after or yielding around filter.
You can control the actions to skip the filter for with the :only
and :except
options, just like when you apply the filters.
531 532 533 |
# File 'lib/action_controller/filters.rb', line 531 def skip_filter(*filters) filter_chain.skip_filter_in_chain(*filters) end |