The flash message is useful for notifying user. Rails 3 allows simple manipulation of the flash message.
1. Add the flash message in app/views/layouts/application.html.erb
...
<body>
...
<% flash.each do |key, value| %>
<%= content_tag(:div, value, :class => "flash #{key}") %>
<% end %>
...
</body>
...
2. Try to add flash message when you want to redirect in the controller
... redirect_to root_path, :notice => "You Flash Message!!" ...
3. You can also add the flash message in the controller in the following way
... if @service.save flash[:success] = "Service created!" redirect_to services_path else flash[:alert] = "Cannot create service!" render 'services/new' end ...
Done =)
Reference: Ruby on Rails Tutorial: Learn Rails by Example – The flash
