aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/actioncontroller
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-10-05 22:16:26 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-10-05 22:16:26 +0100
commita2932784bb71e72a78c32819ebd7ed2bed551e3e (patch)
tree99bfd589a48153e33f19ae72baa6e98f5708a9b8 /railties/doc/guides/actioncontroller
parent4df45d86097efbeabceecfe53d8ea2da9ccbb107 (diff)
downloadrails-a2932784bb71e72a78c32819ebd7ed2bed551e3e.tar.gz
rails-a2932784bb71e72a78c32819ebd7ed2bed551e3e.tar.bz2
rails-a2932784bb71e72a78c32819ebd7ed2bed551e3e.zip
Merge docrails
Diffstat (limited to 'railties/doc/guides/actioncontroller')
-rw-r--r--railties/doc/guides/actioncontroller/actioncontroller.txt28
-rw-r--r--railties/doc/guides/actioncontroller/cookies.txt26
-rw-r--r--railties/doc/guides/actioncontroller/filters.txt118
-rw-r--r--railties/doc/guides/actioncontroller/http_auth.txt24
-rw-r--r--railties/doc/guides/actioncontroller/introduction.txt7
-rw-r--r--railties/doc/guides/actioncontroller/methods.txt37
-rw-r--r--railties/doc/guides/actioncontroller/parameter_filtering.txt14
-rw-r--r--railties/doc/guides/actioncontroller/params.txt62
-rw-r--r--railties/doc/guides/actioncontroller/request_response_objects.txt35
-rw-r--r--railties/doc/guides/actioncontroller/rescue.txt3
-rw-r--r--railties/doc/guides/actioncontroller/session.txt130
-rw-r--r--railties/doc/guides/actioncontroller/streaming.txt91
-rw-r--r--railties/doc/guides/actioncontroller/verification.txt3
13 files changed, 578 insertions, 0 deletions
diff --git a/railties/doc/guides/actioncontroller/actioncontroller.txt b/railties/doc/guides/actioncontroller/actioncontroller.txt
new file mode 100644
index 0000000000..c5a594d713
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/actioncontroller.txt
@@ -0,0 +1,28 @@
+Action Controller basics
+=======================
+
+In this guide you will learn how controllers work and how they fit into the request cycle in your application. You will learn how to make use of the many tools provided by Action Controller to work with the session, cookies and filters and how to use the built-in HTTP authentication and data streaming facilities. In the end, we will take a look at some tools that will be useful once your controllers are ready and working, like how to filter sensitive parameters from the log and how to rescue and deal with exceptions that may be raised during the request.
+
+include::introduction.txt[]
+
+include::methods.txt[]
+
+include::params.txt[]
+
+include::session.txt[]
+
+include::cookies.txt[]
+
+include::filters.txt[]
+
+include::request_response_objects.txt[]
+
+include::http_auth.txt[]
+
+include::streaming.txt[]
+
+include::parameter_filtering.txt[]
+
+include::verification.txt[]
+
+include::rescue.txt[]
diff --git a/railties/doc/guides/actioncontroller/cookies.txt b/railties/doc/guides/actioncontroller/cookies.txt
new file mode 100644
index 0000000000..a845e452b2
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/cookies.txt
@@ -0,0 +1,26 @@
+== Cookies ==
+
+Your application can store small amounts of data on the client - called cookies - that will be persisted across requests and even sessions. Rails provides easy access to cookies via the `cookies` method, which - much like the `session` - works like a hash:
+
+TODO: Find a real-world example where cookies are used
+
+[source, ruby]
+-----------------------------------------
+class FooController < ApplicationController
+
+ def foo
+ cookies[:foo] = "bar"
+ end
+
+ def display_foo
+ @foo = cookies[:foo]
+ end
+
+ def remove_foo
+ cookies.delete(:foo)
+ end
+
+end
+-----------------------------------------
+
+Note that while for session values, you set the key to `nil`, to delete a cookie value, you use `cookies.delete(:key)`.
diff --git a/railties/doc/guides/actioncontroller/filters.txt b/railties/doc/guides/actioncontroller/filters.txt
new file mode 100644
index 0000000000..2baf92d6ef
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/filters.txt
@@ -0,0 +1,118 @@
+== Filters ==
+
+Filters are methods that are run before, after or "around" a controller action. For example, one filter might check to see if the logged in user has the right credentials to access that particular controller or action. Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application. A common, simple filter is one which requires that a user is logged in for an action to be run. Let's define the filter method first:
+
+[source, ruby]
+---------------------------------
+class ApplicationController < ActionController::Base
+
+private
+
+ def require_login
+ unless logged_in?
+ flash[:error] = "You must be logged in to access this section"
+ redirect_to new_login_url # Prevents the current action from running
+ end
+ end
+
+ # The logged_in? method simply returns true if the user is logged in and
+ # false otherwise. It does this by "booleanizing" the current_user method
+ # we created previously using a double ! operator. Note that this is not
+ # common in Ruby and is discouraged unless you really mean to convert something
+ # into true or false.
+ def logged_in?
+ !!current_user
+ end
+
+end
+---------------------------------
+
+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 (a filter which is run before the action) renders or redirects, the action will not run. If there are additional filters scheduled to run after the rendering/redirecting filter, they are also cancelled. To use this filter in a controller, use the "before_filter":http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html#M000704 method:
+
+[source, ruby]
+---------------------------------
+class ApplicationController < ActionController::Base
+
+ before_filter :require_login
+
+end
+---------------------------------
+
+In this example, the filter is added to ApplicationController and thus all controllers in the application. 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, so to prevent this filter from running you can use "skip_before_filter":http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html#M000711 :
+
+[source, ruby]
+---------------------------------
+class LoginsController < Application
+
+ skip_before_filter :require_login, :only => [:new, :create]
+
+end
+---------------------------------
+
+Now, the LoginsController's "new" and "create" actions will work as before without requiring the user to be logged in. The `:only` option is used to only skip this filter for these actions, and there is also an `:except` option which works the other way. These options can be used when adding filters too, so you can add a filter which only runs for selected actions in the first place.
+
+=== After filters and around filters ===
+
+In addition to the before filters, you can run filters after an action has run or both before and after. The after filter is similar to the before filter, but because the action has already been run it has access to the response data that's about to be sent to the client. Obviously, after filters can not stop the action from running. Around filters are responsible for running the action, but they can choose not to, which is the around filter's way of stopping it.
+
+TODO: Find a real example for an around filter
+
+[source, ruby]
+---------------------------------
+class ApplicationController < Application
+
+ around_filter :foo
+
+private
+
+ def foo
+ logger.debug("Action has not been run yet")
+ yield #Run the action
+ logger.debug("Action has been run")
+ end
+
+end
+---------------------------------
+
+=== Other types of filters ===
+
+While the most common way to use filters is by creating private methods and using *_filter to add them, there are two other ways.
+
+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 rewritte to use a block:
+
+[source, ruby]
+---------------------------------
+class ApplicationController < ActionController::Base
+
+ before_filter { |controller| redirect_to new_login_url unless controller.send(:logged_in?) }
+
+end
+---------------------------------
+
+Note that the filter in this case uses `send` because the `logged_in?` method is private and the filter is not run in the scope of the controller. This is not the recommended way to implement this particular filter, but in more simple cases it might be useful.
+
+The second way is to use a class (actually, any object that responds to the right methods will do) to handle the filtering. This is useful in cases that are more complex than can not be implemented in a readable and reusable way using the two other methods. As an example, we will rewrite the login filter again to use a class:
+
+[source, ruby]
+---------------------------------
+class ApplicationController < ActionController::Base
+
+ before_filter LoginFilter
+
+end
+
+class LoginFilter
+
+ def self.filter(controller)
+ unless logged_in?
+ controller.flash[:error] = "You must be logged in to access this section"
+ controller.redirect_to controller.new_login_url
+ end
+ end
+
+end
+---------------------------------
+
+Again, this is not an ideal example for this filter, because it's not run in the scope of the controller but gets it passed as an argument. The filter class has a class method `filter` which gets run before or after the action, depending on if it's a before or after filter. Classes used as around filters can also use the same `filter` method, which will get run in the same way. The method must `yield` to execute the action. Alternatively, it can have both a `before` and an `after` method that are run before and after the action.
+
+The Rails API documentation has "more information and detail on using filters":http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
diff --git a/railties/doc/guides/actioncontroller/http_auth.txt b/railties/doc/guides/actioncontroller/http_auth.txt
new file mode 100644
index 0000000000..5a95de0bb3
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/http_auth.txt
@@ -0,0 +1,24 @@
+== HTTP Basic Authentication ==
+
+Rails comes with built-in HTTP Basic authentication. This is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, we will create an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, "authenticate_or_request_with_http_basic":http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic/ControllerMethods.html#M000610
+
+[source, ruby]
+-------------------------------------
+class AdminController < ApplicationController
+
+ USERNAME, PASSWORD = "humbaba", "f59a4805511bf4bb61978445a5380c6c"
+
+ before_filter :authenticate
+
+private
+
+ def authenticate
+ authenticate_or_request_with_http_basic do |username, password|
+ username == USERNAME && Digest::MD5.hexdigest(password) == PASSWORD
+ end
+ end
+
+end
+-------------------------------------
+
+With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication.
diff --git a/railties/doc/guides/actioncontroller/introduction.txt b/railties/doc/guides/actioncontroller/introduction.txt
new file mode 100644
index 0000000000..35540bbc09
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/introduction.txt
@@ -0,0 +1,7 @@
+== What does a controller do? ==
+
+Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straight-forward as possible.
+
+For most conventional RESTful applications, the controller will receive the request (this is invisible to the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work.
+
+A controller can thus be thought of as a middle man between models and views. It makes the model data available to the view so it can display it to the user, and it saves or updates data from the user to the model.
diff --git a/railties/doc/guides/actioncontroller/methods.txt b/railties/doc/guides/actioncontroller/methods.txt
new file mode 100644
index 0000000000..0818dbb849
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/methods.txt
@@ -0,0 +1,37 @@
+== Methods and actions ==
+
+A controller is a Ruby class which inherits from ActionController::Base and has methods just like any other class. Usually these methods correspond to actions in MVC, but they can just as well be helpful methods which can be called by actions. When your application receives a request, the routing will determine which controller and action to run. Then an instance of that controller will be created and the method corresponding to the action (the method with the same name as the action) is run.
+
+[source, ruby]
+----------------------------------------------
+class ClientsController < ActionController::Base
+
+ # Actions are public methods
+ def new
+ end
+
+ # These methods are responsible for producing output
+ def edit
+ end
+
+# Helper methods are private and can not be used as actions
+private
+
+ def foo
+ end
+
+end
+----------------------------------------------
+
+Private methods in a controller are also used as filters, which will be covered later in this guide.
+
+As an example, if the user goes to `/clients/new` in your application to add a new client, a ClientsController instance will be created and the `new` method will be run. Note that the empty method from the example above could work just fine because Rails will by default render the `new.html.erb` view unless the action says otherwise. The `new` method could make available to the view a `@client` instance variable by creating a new Client:
+
+[source, ruby]
+----------------------------------------------
+def new
+ @client = Client.new
+end
+----------------------------------------------
+
+The Layouts & rendering guide explains this in more detail.
diff --git a/railties/doc/guides/actioncontroller/parameter_filtering.txt b/railties/doc/guides/actioncontroller/parameter_filtering.txt
new file mode 100644
index 0000000000..dce4b252c3
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/parameter_filtering.txt
@@ -0,0 +1,14 @@
+== Parameter filtering ==
+
+Rails keeps a log file for each environment (development, test and production) in the "log" folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The "filter_parameter_logging":http://api.rubyonrails.org/classes/ActionController/Base.html#M000837 can be used to filter out sensitive information from the log. It works by replacing certain keys in the `params` hash with "[FILTERED]" before they are written to the log. As an example, let's see how to filter all parameters with keys that include "password":
+
+[source, ruby]
+-------------------------
+class ApplicationController < ActionController::Base
+
+ filter_parameter_logging :password
+
+end
+-------------------------
+
+The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in return and replaces those for which the block returns true.
diff --git a/railties/doc/guides/actioncontroller/params.txt b/railties/doc/guides/actioncontroller/params.txt
new file mode 100644
index 0000000000..67f97b6135
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/params.txt
@@ -0,0 +1,62 @@
+== Parameters ==
+
+You will probably want to access data sent in by the user or other parameters in your controller actions. There are two kinds of parameters possible in a web application. The first are parameters that are sent as part of the URL, query string parameters. The query string is everything after "?" in the URL. The second type of parameter is usually referred to as POST data. This information usually comes from a HTML form which has been filled in by the user. It's called POST data because it can only be sent as part of an HTTP POST request. Rails does not make any distinction between query string parameters and POST parameters, and both are available in the `params` hash in your controller:
+
+[source, ruby]
+-------------------------------------
+class ClientsController < ActionController::Base
+
+ # This action uses query string parameters because it gets run by a HTTP GET request,
+ # but this does not make any difference to the way in which the parameters are accessed.
+ # The URL for this action would look like this in order to list activated clients: /clients/?status=activated
+ def index
+ if params[:status] = "activated"
+ @clients = Client.activated
+ else
+ @clients = Client.unativated
+ end
+ end
+
+ # This action uses POST parameters. They are most likely coming from an HTML
+ # form which the user has submitted. The URL for this RESTful request will
+ # be "/clients", and the data will be sent as part of the request body.
+ def create
+ @client = Client.new(params[:client])
+ if @client.save
+ redirect_to @client
+ else
+ # This line overrides the default rendering behavior, which would have been
+ # to render the "create" view.
+ render :action => "new"
+ end
+ end
+
+end
+-------------------------------------
+
+=== Hash and array parameters ===
+
+The params hash is not limited to one-dimensional keys and values. It can contain arrays and (nested) hashes. To send an array of values, append "[]" to the key name:
+
+-------------------------------------
+GET /clients?ids[]=1&ids[2]&ids[]=3
+-------------------------------------
+
+The value of `params[:ids]` will now be `["1", "2", "3"]`. Note that parameter values are always strings; Rails makes no attempt to guess or cast the type.
+
+To send a hash you include the key name inside the brackets:
+
+-------------------------------------
+<form action="/clients">
+ <input type="text" name="client[name]" value="Acme" />
+ <input type="text" name="client[phone]" value="12345" />
+ <input type="text" name="client[address][postcode]" value="12345" />
+ <input type="text" name="client[address][city]" value="Carrot City" />
+</form>
+-------------------------------------
+
+The value of `params[:client]` when this form is submitted will be `{:name => "Acme", :phone => "12345", :address => {:postcode => "12345", :city => "Carrot City"}}`. Note the nested hash in `params[:client][:address]`.
+
+=== Routing parameters ===
+
+The `params` hash will always contain the `:controller` and `:action` keys, but you should use the methods `controller_name` and `action_name` instead to access these values. Any other parameters defined by the routing, such as `:id` will also be available.
diff --git a/railties/doc/guides/actioncontroller/request_response_objects.txt b/railties/doc/guides/actioncontroller/request_response_objects.txt
new file mode 100644
index 0000000000..d335523a25
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/request_response_objects.txt
@@ -0,0 +1,35 @@
+== The request and response objects ==
+
+In every controller there are two accessor methods pointing to the request and the response objects associated with the request cycle that is currently in execution. The `request` method contains an instance of "AbstractRequest":http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html and the `response` method contains the "response object":http://github.com/rails/rails/tree/master/actionpack/lib/action_controller/response.rb representing what is going to be sent back to the client.
+
+=== The request ===
+
+The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the "Rails API documentation":http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html
+
+ * host - The hostname used for this request.
+ * domain - The hostname without the first part (usually "www").
+ * format - The content type requested by the client.
+ * method - The HTTP method used for the request.
+ * get?, post?, put?, delete?, head? - Returns true if the HTTP method is get/post/put/delete/head.
+ * headers - Returns a hash containing the headers associated with the request.
+ * port - The port number (integer) used for the request.
+ * protocol - The protocol used for the request.
+ * query_string - The query string part of the URL - everything after "?".
+ * remote_ip - The IP address of the client.
+ * url - The entire URL used for the request.
+
+==== path_parameters, query_parameters and request_parameters ====
+
+TODO: Does this belong here?
+
+Rails collects all of the parameters sent along with the request in the `params` hash, whether they are sent as part of the query string or the post body. The request object has three accessors that give you access to these parameters depending on where they came from. The `query_parameters` hash contains parameters that were sent as part of the query string while the `request_parameters` hash contains parameters sent as part of the post body. The `path_parameters` hash contains parameters that were recognised by the routing as being part of the path leading to this particular controller and action.
+
+=== The response ===
+
+The response objects is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values.
+
+ * body - This is the string of data being sent back to the client. This is most often HTML.
+ * status - The HTTP status code for the response, like 200 for a successful request or 404 for file not found.
+ * location - The URL the client is being redirected to, if any.
+ * content_type - The content type of the response.
+ * charset - The character set being used for the response. Default is "utf8".
diff --git a/railties/doc/guides/actioncontroller/rescue.txt b/railties/doc/guides/actioncontroller/rescue.txt
new file mode 100644
index 0000000000..6ff7ea67d8
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/rescue.txt
@@ -0,0 +1,3 @@
+== Rescue ==
+
+Describe how to use rescue_from et al to rescue exceptions in controllers.
diff --git a/railties/doc/guides/actioncontroller/session.txt b/railties/doc/guides/actioncontroller/session.txt
new file mode 100644
index 0000000000..50ed76e3ae
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/session.txt
@@ -0,0 +1,130 @@
+== Session ==
+
+Your application sets up a session for each user which can persist small amounts of data between requests. The session is only available in the controller. It can be stored in a number of different session stores:
+
+TODO: Not sure if all of these are available by default.
+
+ * CookieStore - Stores everything on the client.
+ * SQLSessionStore - Stores the data in a database using SQL.
+ * DRBStore - Stores the data on a DRb client.
+ * MemCacheStore - Stores the data in MemCache.
+ * ActiveRecordStore - Stores the data in a database using Active Record.
+
+All session stores store the session id in a cookie - there is no other way of passing it to the server. Most stores also use this key to locate the session data on the server.
+
+The default and recommended store, the Cookie Store, does not store session data on the server, but in the cookie itself. The data is cryptographically signed to make it tamper-proof, but it is not encrypted, so anyone with access to it can read its contents. It can only store 4Kb of data - much less than the others - but this is usually enough. Storing large amounts of data is discouraged no matter which session store your application uses. Expecially discouraged is storing complex objects (anything other than basic Ruby objects) in the session, as the server might not be able to reassemble them between requests, which will result in an error. The Cookie Store has the added advantage that it does not require any setting up beforehand - Rails will generate a "secret key" which will be used to sign the cookie when you create the application.
+
+If you need a different session storage mechanism, you can change it in the `config/environment.rb` file:
+
+[source, ruby]
+------------------------------------------
+# Set to one of [:active_record_store, :sql_session_store, :drb_store, :mem_cache_store, :cookie_store]
+config.action_controller.session_store = :active_record_store
+------------------------------------------
+
+=== Accessing the session ===
+
+In your controller you can access the session through the `session` method. Session values are stored using key/value pairs like a hash:
+
+[source, ruby]
+------------------------------------------
+class ApplicationController < ActionController::Base
+
+private
+
+ # Finds the User with the ID stored in the session with the key :current_user_id
+ def current_user
+ @_current_user ||= session[:current_user_id] && User.find(session[:current_user_id])
+ end
+
+end
+------------------------------------------
+
+To store something in the session, just assign it to the key like a hash:
+
+[source, ruby]
+------------------------------------------
+class LoginsController < ApplicationController
+
+ # "Create" a login, aka "log the user in"
+ def create
+ if user = User.authenticate(params[:username, params[:password])
+ # Save the user ID in the session so it can be used in subsequent requests
+ session[:current_user_id] = user.id
+ redirect_to root_url
+ end
+ end
+
+end
+------------------------------------------
+
+To remove something from the session, assign that key to be `nil`:
+
+[source, ruby]
+------------------------------------------
+class LoginsController < ApplicationController
+
+ # "Delete" a login, aka "log the user out"
+ def destroy
+ # Remove the user id from the session
+ session[:current_user_id] = nil
+ redirect_to root_url
+ end
+
+end
+------------------------------------------
+
+To reset the entire session, use `reset_session`.
+
+=== The flash ===
+
+The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash. Let's use the act of logging out as an example. The controller can set a message which will be displayed to the user on the next request:
+
+[source, ruby]
+------------------------------------------
+class LoginsController < ApplicationController
+
+ def destroy
+ session[:current_user_id] = nil
+ flash[:notice] = "You have successfully logged out"
+ redirect_to root_url
+ end
+
+end
+------------------------------------------
+
+The `destroy` action redirects to the application's `root_url`, where the message will be displayed. Note that it's entirely up to the next action to decide what, if anything, it will do with what the previous action put in the flash. It's conventional to a display eventual errors or notices from the flash in the application's layout:
+
+[source, ruby]
+------------------------------------------
+<!-- head, etc -->
+<body>
+ <% if flash[:notice] -%>
+ <p class="notice"><%= flash[:notice] %></p>
+ <% end -%>
+ <% if flash[:error] -%>
+ <p class="error"><%= flash[:error] %></p>
+ <% end -%>
+ <!-- more content -->
+</body>
+</html>
+------------------------------------------
+
+This way, if an action sets an error or a notice message, the layout will display it automatically.
+
+If you want a flash value to be carried over to another request, use the `keep` method:
+
+[source, ruby]
+------------------------------------------
+class MainController < ApplicationController
+
+ # Let's say this action corresponds to root_url, but you want all requests here to be redirected to
+ # UsersController#index. If an action sets the flash and redirects here, the values would normally be
+ # lost when another redirect happens, but you can use keep to make it persist for another request.
+ def index
+ flash.keep # Will persist all flash values. You can also use a key to keep only that value: flash.keep(:notice)
+ redirect_to users_url
+ end
+
+end
+------------------------------------------
diff --git a/railties/doc/guides/actioncontroller/streaming.txt b/railties/doc/guides/actioncontroller/streaming.txt
new file mode 100644
index 0000000000..6026a8c51b
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/streaming.txt
@@ -0,0 +1,91 @@
+== Streaming and file downloads ==
+
+Sometimes you may want to send a file to the user instead of rendering an HTML page. All controllers in Rails have the "send_data":http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000624 and the "send_file":http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000623 methods, that will both stream data to the client. `send_file` is a convenience method which lets you provide the name of a file on the disk and it will stream the contents of that file for you.
+
+To stream data to the client, use `send_data`:
+
+[source, ruby]
+----------------------------
+require "prawn"
+class ClientsController < ApplicationController
+
+ # Generate a PDF document with information on the client and return it.
+ # The user will get the PDF as a file download.
+ def download_pdf
+ client = Client.find(params[:id])
+ send_data(generate_pdf, :filename => "#{client.name}.pdf", :type => "application/pdf")
+ end
+
+private
+
+ def generate_pdf(client)
+ Prawn::Document.new do
+ text client.name, :align => :center
+ text "Address: #{client.address}"
+ text "Email: #{client.email}"
+ end.render
+ end
+
+end
+----------------------------
+
+The `download_pdf` action in the example above will call a private method which actually generates the file (a PDF document) and returns it as a string. This string will then be streamed to the client as a file download and a filename will be suggested to the user. Sometimes when streaming files to the user, you may not want them to download the file. Take images, for example, which can be embedded into HTML pages. To tell the browser a file is not meant to be downloaded, you can set the `:disposition` option to "inline". The opposite and default value for this option is "attachment".
+
+=== Sending files ===
+
+If you want to send a file that already exists on disk, use the `send_file` method. This is usually not recommended, but can be useful if you want to perform some authentication before letting the user download the file.
+
+[source, ruby]
+----------------------------
+class ClientsController < ApplicationController
+
+ # Stream a file that has already been generated and stored on disk
+ def download_pdf
+ client = Client.find(params[:id])
+ send_data("#{RAILS_ROOT}/files/clients/#{client.id}.pdf", :filename => "#{client.name}.pdf", :type => "application/pdf")
+ end
+
+end
+----------------------------
+
+NOTE: Be careful when using (or just don't use) "outside" data (params, cookies, etc) to locate the file on disk, as this is a security risk as someone could gain access to files they are not meant to have access to.
+
+NOTE: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack.
+
+This will read and stream the file 4Kb at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the `stream` option or adjust the block size with the `buffer_size` option.
+
+=== RESTful downloads ===
+
+While `send_data` works just fine, if you are creating a RESTful application having separate actions for file downloads is a bit ugly. In REST terminology, the PDF file from the example above can be considered just another representation of the client resource. Rails provides an easy and quite sleek way of doing "RESTful downloads". Let's try to rewrite the example so that the PDF download is a part of the `show` action:
+
+[source, ruby]
+----------------------------
+class ClientsController < ApplicationController
+
+ # The user can request to receive this resource as HTML or PDF.
+ def show
+ @client = Client.find(params[:id])
+
+ respond_to do |format|
+ format.html
+ format.pdf{ render :pdf => generate_pdf(@client) }
+ end
+ end
+
+end
+----------------------------
+
+In order for this example to work, we have to add the PDF MIME type to Rails. This can be done by adding the following line to the file `config/initializers/mime_types.rb`:
+
+[source, ruby]
+----------------------------
+Mime::Type.register "application/pdf", :pdf
+----------------------------
+
+NOTE: Configuration files are not reloaded on each request, so you have to restart the server in order for their changes to take effect.
+
+Now the user can request to get a PDF version of a client just by adding ".pdf" to the URL:
+
+----------------------------
+GET /clients/1.pdf
+----------------------------
diff --git a/railties/doc/guides/actioncontroller/verification.txt b/railties/doc/guides/actioncontroller/verification.txt
new file mode 100644
index 0000000000..129ff7e7b0
--- /dev/null
+++ b/railties/doc/guides/actioncontroller/verification.txt
@@ -0,0 +1,3 @@
+== Verification ==
+
+Describe how to use the verify methods to make sure some prerequisites are met before an action gets run