You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The method simply stores an error message in the flash and redirects to the login form if the user is not logged in. If a "before" filter renders or redirects, the action will not run. If there are additional filters scheduled to run after that filter, they are also cancelled.
460
460
461
-
In this example the filter is added to `ApplicationController` and thus all controllers in the application inherit it. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn't be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with `skip_before_filter`:
461
+
In this example the filter is added to `ApplicationController` and thus all controllers in the application inherit it. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn't be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with `skip_before_action`:
@@ -480,7 +480,7 @@ For example, in a website where changes have an approval workflow an administrat
480
480
481
481
```ruby
482
482
classChangesController < ActionController::Base
483
-
around_filter:wrap_in_transaction, only::show
483
+
around_action:wrap_in_transaction, only::show
484
484
485
485
private
486
486
@@ -502,13 +502,13 @@ You can choose not to yield and build the response yourself, in which case the a
502
502
503
503
### Other Ways to Use Filters
504
504
505
-
While the most common way to use filters is by creating private methods and using *_filter to add them, there are two other ways to do the same thing.
505
+
While the most common way to use filters is by creating private methods and using *_action to add them, there are two other ways to do the same thing.
506
506
507
-
The first is to use a block directly with the *_filter methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block:
507
+
The first is to use a block directly with the *_action methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block:
Copy file name to clipboardExpand all lines: guides/source/action_view_overview.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1486,7 +1486,7 @@ You can use the same technique to localize the rescue files in your public direc
1486
1486
Since Rails doesn't restrict the symbols that you use to set I18n.locale, you can leverage this system to display different content depending on anything you like. For example, suppose you have some "expert" users that should see different pages from "normal" users. You could add the following to `app/controllers/application.rb`:
Copy file name to clipboardExpand all lines: guides/source/i18n.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -134,10 +134,10 @@ However, you would probably like to **provide support for more locales** in your
134
134
135
135
WARNING: You may be tempted to store the chosen locale in a _session_ or a <em>cookie</em>, however **do not do this**. The locale should be transparent and a part of the URL. This way you won't break people's basic assumptions about the web itself: if you send a URL to a friend, they should see the same page and content as you. A fancy word for this would be that you're being [<em>RESTful</em>](http://en.wikipedia.org/wiki/Representational_State_Transfer. Read more about the RESTful approach in [Stefan Tilkov's articles](http://www.infoq.com/articles/rest-introduction). Sometimes there are exceptions to this rule and those are discussed below.
136
136
137
-
The _setting part_ is easy. You can set the locale in a `before_filter` in the `ApplicationController` like this:
137
+
The _setting part_ is easy. You can set the locale in a `before_action` in the `ApplicationController` like this:
@@ -203,7 +203,7 @@ This solution has aforementioned advantages, however, you may not be able or may
203
203
204
204
### Setting the Locale from the URL Params
205
205
206
-
The most usual way of setting (and passing) the locale would be to include it in URL params, as we did in the `I18n.locale = params[:locale]`_before_filter_ in the first example. We would like to have URLs like `www.example.com/books?locale=ja` or `www.example.com/ja/books` in this case.
206
+
The most usual way of setting (and passing) the locale would be to include it in URL params, as we did in the `I18n.locale = params[:locale]`_before_action_ in the first example. We would like to have URLs like `www.example.com/books?locale=ja` or `www.example.com/ja/books` in this case.
207
207
208
208
This approach has almost the same set of advantages as setting the locale from the domain name: namely that it's RESTful and in accord with the rest of the World Wide Web. It does require a little bit more work to implement, though.
Copy file name to clipboardExpand all lines: guides/source/security.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -688,7 +688,7 @@ NOTE: _When sanitizing, protecting or verifying something, whitelists over black
688
688
689
689
A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although sometimes it is not possible to create a whitelist (in a SPAM filter, for example), _prefer to use whitelist approaches_:
690
690
691
-
* Use before_filter only: [...] instead of except: [...]. This way you don't forget to turn it off for newly added actions.
691
+
* Use before_action only: [...] instead of except: [...]. This way you don't forget to turn it off for newly added actions.
692
692
* Use attr_accessible instead of attr_protected. See the mass-assignment section for details
693
693
* Allow <strong> instead of removing <script> against Cross-Site Scripting (XSS). See below for details.
0 commit comments