I have the following code in a Rails controller:
flash.now[:notice] = \'Successfully checked in\'
redirect_to check_in_path
Then in the /check_
If you are using Bootstrap, this will display a nicely-formatted flash message on the page that's the target of your redirect.
In your controller:
if my_success_condition
flash[:success] = 'It worked!'
else
flash[:warning] = 'Something went wrong.'
end
redirect_to myroute_path
In your view:
<% flash.each do |key, value| %>
<%= value %>
<% end %>
This will produce HTML like:
It worked!
For available Bootstrap alert styles, see: http://getbootstrap.com/docs/4.0/components/alerts/
Reference: https://agilewarrior.wordpress.com/2014/04/26/how-to-add-a-flash-message-to-your-rails-page/