Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Ruby%20On%20Rails%20Interview%20Questions%20and%20Answers

Question: What is Flash in Ruby on Rails?
Answer:

Flash  is simply a way to pass some value to the next action. 

Anything you place in the flash will be exposed to the very next action and then cleared out.

Here’s an example:

def destroy

section = Section.find(params[:id])      
section.destroy      
FLASH[:NOTICE] = "SECTION DESTROYED."     
redirect_to(:action => 'list', :page_id => @page.id)    

end

Then wherever you want to use the flash you can write this code. I often put this snippet in the application.html.erb file, somewhere towards the top:

   <% if !flash[:notice].blank? %>         
<div class="notice">  
 <%= flash[:notice] %>
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook