Module: Sinatra::Flash::Storage

Defined in:
lib/sinatra/flash/storage.rb

Instance Method Summary collapse

Instance Method Details

#flash(key = :flash) ⇒ FlashHash

The main Sinatra helper for accessing the flash. You can have multiple flash collections (e.g., for different apps in your Rack stack) by passing a symbol to it.

you want to reference. Defaults to ‘:flash’. If there is no session or the key is not found, an empty hash is used. Note that this is only used in the case of multiple flash collections, which is rarer than multiple flash messages.

Parameters:

  • key (optional, String, Symbol) (defaults to: :flash)

    Specifies which key in the session contains the hash

Returns:

  • (FlashHash)

    Assign to this like any other hash.



16
17
18
19
# File 'lib/sinatra/flash/storage.rb', line 16

def flash(key=:flash)
  @flash ||= {}
  @flash[key.to_sym] ||= FlashHash.new((session ? session[key.to_sym] : {}))
end