Skip to content
Get your Rails flash[] out of your controllers and into a YAML
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example
lib
tasks
test
MIT-LICENSE
README.rdoc
Rakefile
init.rb
install.rb

README.rdoc

Flashdance

Flashdance is a drop in replacement for flash in action controller. It stores all your assorted messages in a single YAML file.

The default location for the YAML file is: app/views/shared/flash.yml

You can change this with:

Quirkey::Flashdance::Loader.yml_path = File.join(RAILS_ROOT,'app','views','your_folder','your_flash.yml')

You can email me at aaron at quirkey for bug reports/comments/suggestions

Example

Flashdance bends a lot of different ways:

At its most unobtrusive:

# in your controller
def update
  # . . . booring part where record gets updated
  flash[:warning] = flashdance(:this_failed) #=> This failed
end

A little nicer:

def update
  # . . .
  flash(:message => 'all_is_good') # YAML entries can be referred to by strings or symbols
  # equivalent to flash[:message] = "This is great"
end

ERB is evaluated in the context of the controller so you can do fun things like:

def tell_off_the_spammer
  # . . .
  @email = 'jon@example.com'
  flash(:warning => :using_erb)
  # equivalent to flash[:warning] = "you are an idiot, jon@example.com"
end

So what if your app is huge and you use these flash thingies all over the place? Your YAML file might get big and unreadable. Well, thats why you can nest! Nested sections are refered to by arrays.

def make_a_nest
  #  . . .
  flash(:nest => [:section,:subsection])
  # equivalent to flash[:nest] = "I'm nested"
end

Flashdance automatically checks for entries nested in the controller/action path where you call it from. And heres where you get splashed with that big bucket of water:

class MyController < ApplicationController
  # . . . 

  def my_action
   # . . . where you dance your heart out
   flash(:message)
   # equivalent to flash[:message] = "I'm soaking wet"
  end
end

Read more: www.quirkey.com/blog/

Installation

Latest is the Git on the Hub: github.com/quirkey/flashdance

From Github (legacy):

./script/plugin install git://github.com/quirkey/flashdance.git

Copyright © 2008 Aaron Quint / Quirkey NYC, LLC. , released under the MIT license

Something went wrong with that request. Please try again.