0
0
Ruby on Railsframework~5 mins

Flash messages in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a flash message in Rails?
A flash message is a way to send a one-time message from the controller to the view, usually to show notices or alerts after an action like form submission.
Click to reveal answer
beginner
How long does a flash message last in Rails?
Flash messages last for exactly one request cycle. They appear on the next page load and then disappear automatically.
Click to reveal answer
beginner
How do you set a flash message in a Rails controller?
You set a flash message by assigning a string to flash[:key], for example: flash[:notice] = "Saved successfully".
Click to reveal answer
intermediate
What is the difference between flash and flash.now in Rails?
flash sets a message for the next request, while flash.now sets a message for the current request only, useful when rendering instead of redirecting.
Click to reveal answer
beginner
Where in a Rails view do you usually display flash messages?
Flash messages are usually displayed in the application layout or a shared partial, so they appear on any page after an action.
Click to reveal answer
What does flash[:alert] typically represent in Rails?
AA permanent message
BA success message
CA debug message
DAn error or warning message
Which method shows a flash message immediately without redirecting?
Aflash.now
Bflash.next
Cflash.show
Dflash.set
Where should you place flash message display code in a Rails app?
AIn the application layout or a shared partial
BOnly in the controller
CIn the database
DIn the model
What happens to a flash message after it is displayed once?
AIt repeats twice
BIt stays forever
CIt is cleared automatically
DIt moves to the database
How do you set a success flash message in Rails?
Aflash[:error] = "Success!"
Bflash[:notice] = "Success!"
Cflash[:alert] = "Success!"
Dflash[:fail] = "Success!"
Explain how flash messages work in Rails and how you would use them in a simple form submission.
Think about how you tell a user their form was saved or had errors.
You got /4 concepts.
    Describe the difference between flash and flash.now and when you would use each.
    Consider what happens when you redirect versus render in Rails.
    You got /4 concepts.