Hi everyone,
What’s the difference between Flash and Session? Probably the most
common use of the flash is to pass error and informational strings
from one action to the next. But I wonder why I can’t use session for
this purpose. For example, I found the following piece of code in
“Agile web development with rails”.
Controller:
class BlogController
def display
@article = Article.find(params[:id])
end
def add_comment
@article = Article.find(params[:id])
comment = Comment.new(params[:comment])
@article.comments << comment
if @article.save
flash[:notice] = “Thank you for your valuable comment”
else
flash[:notice] = “We threw your worthless comment away”
end
redirect_to :action => ‘display’
end
end
the following is the layout of the template view:
My Blog
<%= stylesheet_link_tag("blog" ) %>
<% if flash[:notice] -%>
<%= flash[:notice] %>
<% end -%>
<%= yield :layout %>
My question is why we dont use session here to display error
information
On Jul 1, 12:21 am, Xiahong G. [email protected] wrote:
Hi everyone,
What’s the difference between Flash and Session? Probably the most
common use of the flash is to pass error and informational strings
from one action to the next. But I wonder why I can’t use session for
this purpose. For example, I found the following piece of code in
“Agile web development with rails”.
The flash is stored in the session. The only thing that is special
about the flash is that rails takes care of expiring items from it for
you.
Fred
On Jun 30, 2009, at 9:21 PM, Xiahong G. wrote:
Hi everyone,
What’s the difference between Flash and Session? Probably the most
common use of the flash is to pass error and informational strings
from one action to the next. But I wonder why I can’t use session for
this purpose. For example, I found the following piece of code in
“Agile web development with rails”.
session isn’t cleared from request to request. flash is. You could
certainly use session, but you’d need to make sure you did something
like session[:notice] = nil in a before filter otherwise you’d spit
out the same message over and over and over.
-philip
thanks all…
2009/6/30 Philip H. [email protected]