Creating Flash Messages

Flash messages are created in a controller. For example, we can add
messages to the home page by modifying the file
app/controllers/visitors_controller.rb like this:

class VisitorsController < ApplicationController

  def new
    @owner = Owner.new
    flash[:notice] = 'Welcome!'
    flash[:alert] = 'My birthday is soon.'
  end

end

If you test the application after adding the messages to the
VisitorsController, you’ll see two flash messages appear on the page.

Rails provides the flash object so that messages can be created in the
controller and displayed on the rendered web page.

In this example, we create a flash message by associating the object
flash[:notice] with the string 'Welcome!'. We can assign other messages,
such as flash[:alert] or even flash[:warning]. In practice, Rails uses
only :notice and :alert as flash message keys so it is wise to stick
with just these.