Skip to content

Commit

Permalink
Replace before_filter with before_action
Browse files Browse the repository at this point in the history
  • Loading branch information
philtr committed Feb 27, 2016
1 parent 94659a8 commit 2cdadf1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ For example, restrict the second list item to only users that have logged in:
</ul>
```

Controllers can also be restricted using `before_filter`:
Controllers can also be restricted using `before_action`:

```ruby
class WidgetsController < ApplicationController
before_filter :signin_required
before_action :signin_required

# ...
end
Expand All @@ -91,7 +91,7 @@ class WidgetsController < ApplicationController
end
```

All normal Rails `before_filter` options apply, so you can always limit this restriction to a specific action:
All normal Rails `before_action` options apply, so you can always limit this restriction to a specific action:


```ruby
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if defined?(ApplicationController)
class SessionsController < ApplicationController
before_filter :destroy_session, except: :create
before_action :destroy_session, except: :create

unloadable

Expand Down
8 changes: 4 additions & 4 deletions lib/challah/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Controller
module ClassMethods
# Restrict the current controller to only users that have authenticated. All actions
# in the controller will be restricted unless otherwise stated. All normal options
# for a before_filter are observed.
# for a before_action are observed.
#
# @example
# class YourController < ApplicationController
Expand All @@ -29,7 +29,7 @@ module ClassMethods
#
# @see Controller::InstanceMethods#signin_required signin_required
def restrict_to_authenticated(options = {})
before_filter(options) do |controller|
before_action(options) do |controller|
controller.send(:signin_required)
end
end
Expand Down Expand Up @@ -90,14 +90,14 @@ def current_user_session
#
# @example
# class YourController < ApplicationController
# before_filter :login_required
# before_action :login_required
#
# # ...
# end
#
# @example Specifing certain actions.
# class YourOtherController < ApplicationController
# before_filter :login_required, :only => [ :create, :update, :destroy ]
# before_action :login_required, :only => [ :create, :update, :destroy ]
#
# # ...
# end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/controllers/restrictions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This controller is only used for testing purposes, it does not actually get used outside of test.
class RestrictionsController < ApplicationController
signin_required only: [ :blah ]
before_filter :signin_required, only: [ :edit ]
before_action :signin_required, only: [ :edit ]
restrict_to_authenticated only: [ :show ]

def index
Expand Down

0 comments on commit 2cdadf1

Please sign in to comment.