Skip to content

Commit

Permalink
Add description of flash.now
Browse files Browse the repository at this point in the history
  • Loading branch information
toretore authored and karmi committed Oct 14, 2008
1 parent b38a803 commit 53f5696
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions railties/doc/guides/actioncontroller/session.txt
Expand Up @@ -162,3 +162,24 @@ class MainController < ApplicationController


end end
------------------------------------------ ------------------------------------------

==== flash.now ====

By default, adding values to the flash will make them available to the next request, but sometimes you may want to access those values in the same request. For example, if the `create` action fails to save a resource and you render the `new` template directly, that's not going to result in a new request, but you may still want to display a message using the flash. To do this, you can use `flash.now` in the same way you use the normal `flash`:

[source, ruby]
------------------------------------------
class ClientsController < ApplicationController

def create
@client = Client.new(params[:client])
if @client.save
# ...
else
flash.now[:error] = "Could not save client"
render :action => "new"
end
end

end
------------------------------------------

0 comments on commit 53f5696

Please sign in to comment.