Skip to content
This repository has been archived by the owner on Nov 23, 2018. It is now read-only.

Flash Messages

TrueNorth edited this page Jun 16, 2012 · 3 revisions

Setup

Put this in your layout file wherever you want to render the flash messages

<%= spurs_flash_helper %>

and flash messages will be automatically rendered on page loads

Usage

From the rails side

By default, you can create four types of messages

flash_addItem(:notices,"A message about something successfully happening!")
flash_addItem(:warnings, "Something is unusual, but not absolutely critical")
flash_addItem(:errors, "Something critical has happened")
flash_addItem(:infos, "Here's some information")

You can also create multiple messages for each type

flash_addItem(:errors, "Problem validating phone number")
flash_addItem(:errors, "Problem validating street address")

And it's especially easy to add model errors as flash messages. Here's a typical usage

m = Message.new(:title => "hello", :body => "world!")
if !m.save
  flash_addModelErrors(m)
else
  flash_addItem(:notices,"Created a new message! Throw yourself a party.")
end

From the javascript side

You can also create matching flash messages via javascript

spurs.flash.alert("Something has gone wrong!","error");

for the singular versions of each of the four types above ("info", "warning", "error", "notice")

Clone this wiki locally