Skip to content

Commit 61c75b3

Browse files
committed
Support controller callbacks for Rails 3..5
`before_filter` is deprecated in Rails 5 and will disappear in 5.1 This change begins using `before_action`, with a fallback to `before_filter` if `before_action` is not available. closes #404
1 parent 3d3b0e5 commit 61c75b3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/react/rails/controller_lifecycle.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ module ControllerLifecycle
44
extend ActiveSupport::Concern
55

66
included do
7-
# use old names to support Rails 3
8-
before_filter :setup_react_component_helper
9-
after_filter :teardown_react_component_helper
7+
# use both names to support Rails 3..5
8+
before_action_with_fallback = begin method(:before_action); rescue method(:before_filter); end
9+
after_action_with_fallback = begin method(:after_action); rescue method(:after_filter); end
10+
before_action_with_fallback.call :setup_react_component_helper
11+
after_action_with_fallback.call :teardown_react_component_helper
1012
attr_reader :__react_component_helper
1113
end
1214

0 commit comments

Comments
 (0)