To get these nice Twitter Bootstrap alerts to show up in your Rails application

screen-shot-2016-12-04-at-4-08-53-pm

Emit them from your Rails app like this.

SomeController

 class SomeController < ApplicationController

  before_action :last_page

  def what_is_automated_testing
    flash[:success] = 'Success'
    flash[:info] = 'Info'
    flash[:warning] = 'Warning'
    flash[:danger] = 'Danger'
    render layout: "static_page_with_sidebar"
  end

Now, if you have Twitter bootstrap correctly configured, you should see this.

screen-shot-2016-12-04-at-4-13-29-pm

If you are wondering why you don’t see this styling with the rest of your application, it’s because Rails by default doesn’t use this hashes (success, info, warning, etc) for it’s messages. It uses ‘notice’ and others instead (though some may overlap) which is defined in the defaul scaffold.scss so beware of that.

Happy styling!

Links that help

https://agilewarrior.wordpress.com/2014/04/26/how-to-add-a-flash-message-to-your-rails-page/
http://getbootstrap.com/components/#alerts

 

Advertisements