Skip to content

lhoeg/display_flash_helper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DisplayFlashHelper
==================

Just a little helper to make it easier to display notice, warning, and error messages. It will only show flash[:success], flash[:notice], flash[:warning], or flash[:error] messages.

There are some default styles and icons that can be used.  

  rake display_helper:setup

Example
=======

In your controller:

  def create
    do_somthing
    flash[:notice] = 'Something has been done.'
  end

In your view (layout or template):

  <%= display_flash %>

And it will create:
  <div id="flash">
    <div class="notice">Something has been done.</div>
  </div>

Include the stylesheet in the <head> section of your layout:

  <%= stylesheet_link_tag 'display_flash_helper' %>

or Geoffrey Dagley's original stylesheet:

  <%= stylesheet_link_tag 'flash_styles' %>

Configuring
===========

Options for display_flash_helper are optional and get their default values from the DisplayFlashHelper.flash_options hash.
You can write to this hash to override default values on the global level:

  DisplayFlashHelper.flash_options[:error_class] = 'my_error'

Available options (and their defaults) are:

  :flash_types    => [:success, :notice, :warning, :error]
  :success_class  => 'success'
  :notice_class   => 'notice'
  :warning_class  => 'warning'
  :error_class    => 'error'
  :flash_id       => 'flash'

Default flash messages
======================

Add the following to ApplicationController (app/controllers/application.rb):

  include DisplayFlashHelper::FlashHelperMethods

The following flash helper methods are now available for controllers instead of the static flash[:notice] = 'Note was successfully created.'-like messages:

  flash_created(@object)
  flash_create_failed(@object)
  flash_updated(@object)
  flash_update_failed(@object)

Add the following to your I18n locale file (e.g. RAILS_ROOT/config/locales/#{I18n.locale}.local.yml):

  display_flash_helper:
    created: "{{obj}} was successfully created."
    create_failed: "{{obj}} could not be created."
    updated: "{{obj}} was successfully updated."
    update_failed: "{{obj}} could not be updated."

TODO
====

- Use Rails I18n in flash helper methods;
You may want to define/translate human names for objects in your I18n locale file; for example:

  activerecord:
    models:
      user: "Employee"
      ...

- Use CSS sprite to combine images into one

Notes
=====

Style thanks to Janko Jovanovic's post http://www.jankoatwarpspeed.com/post/2008/05/22/CSS-Message-Boxes-for-different-message-types.aspx
Knob Buttons Toolbar icons from http://itweek.deviantart.com/art/Knob-Buttons-Toolbar-icons-73463960
Silk Icons from http://famfamfam.com/lab/icons/silk/, released under the Creative Commons Attribution 2.5 License

To display transparent png images correctly in IE6, see Angus Turnbull's solution http://www.twinhelix.com/css/iepngfix/

Copyright (c) 2008 Geoffrey Dagley, released under the MIT license

About

Trying to make displaying flash messages easier and prettier

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%