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: <head> <title>My Blog</title> <%= stylesheet_link_tag("blog" ) %> </head> <body> <div id="main" > <% if flash[:notice] -%> <div id="notice" ><%= flash[:notice] %></div> <% end -%> <%= yield :layout %> </div> </body> </html>
My question is why we dont use session here to display error information