No commit activity in last 3 years
No release in over 3 years
A simple Rails view helper which displays one or more HTML `div`s with the `flash` messages.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Crystal Flash Messages

Build Status Gem version Code Climate

A simple Rails view helper which displays one or more HTML divs with the flash messages.

Install

The installation is pretty standard, add the following line to your Gemfile, then run bundle install:

gem 'crystal_flash_messages'

What this gem does / How to use

This gem allows you to use a view helper called crystal_flash_messages.
The wrapper div has Bootstrap-friendly classes.

Typically, you would add this to app/views/layouts/application.html.erb:

<%= crystal_flash_messages %>

... which, for flash[:error] = "Test" would generate:

<div class="alert alert-danger flash-error" role="alert">
  Test
</div>

Complete list of CSS classes generated for the helper:

# Smart
flash[:error] # => 'alert alert-danger flash-error'
flash[:notice] # => 'alert alert-info flash-notice'
# Basic
flash[:info] # => 'alert alert-info flash-info'
flash[:warning] # => 'alert alert-warning flash-warning'
flash[:foobar] # => 'alert alert-foobar flash-foobar'

What this gem doesn't do

  • Include any other dependencies
  • Add any kind of behavior to the flash object itself
  • Inject or execute any code in your controllers
  • Anything not listed in "What this gem does"

Optional configuration

You can change the default behavior of crystal_flash_messages by:

Setting an initializer

Create a file config/initializers/crystal_flash_messages.rb and replace one of the defaults:

CrystalErrorMessages.configure do |config|
  # This string will be added to the list of HTML classes
  config.additional_classes = String.new
end

Passing options when calling crystal_flash_messages

Examples:

<%= crystal_flash_messages(additional_classes: 'special-flash') %>

Contributing

Don't hesitate to send a pull request!

Testing

$ bundle install
$ bundle exec rspec spec/

License

This software is distributed under the MIT License. Copyright (c) 2016-2019, Christophe Maximin