module Voltron::Flash
Constants
- VERSION
Public Class Methods
prepended(base)
click to toggle source
# File lib/voltron/flash.rb, line 8 def self.prepended(base) base.send :after_action, :include_flash_later end
Public Instance Methods
flash!(**flashes)
click to toggle source
# File lib/voltron/flash.rb, line 22 def flash!(**flashes) flashes.symbolize_keys.each do |type,messages| stored_flashes[type] ||= [] stored_flashes[type] += Array.wrap(messages) end # Set the headers initially. If redirecting, they will be removed as the flash will instead be a part of `flash` response.headers[Voltron.config.flash.header] = stored_flashes.to_json end
redirect_to(options={}, response_status={})
click to toggle source
Calls superclass method
# File lib/voltron/flash.rb, line 17 def redirect_to(options={}, response_status={}) include_flash_later super end
render(*args)
click to toggle source
Calls superclass method
# File lib/voltron/flash.rb, line 12 def render(*args) include_flash_now super end
Private Instance Methods
include_flash_later()
click to toggle source
When redirecting, remove the flash from the headers (unless ajax request), append it all to the `flash` object
# File lib/voltron/flash.rb, line 45 def include_flash_later unless request.xhr? response.headers.except! Voltron.config.flash.header stored_flashes.each { |type,messages| flash[type] = messages } end end
include_flash_now()
click to toggle source
Before rendering, include any flash messages in flash.now, so they will be available when the page is rendered
# File lib/voltron/flash.rb, line 40 def include_flash_now stored_flashes.each { |type,messages| flash.now[type] = messages } end
stored_flashes()
click to toggle source
# File lib/voltron/flash.rb, line 34 def stored_flashes @stored_flashes ||= {} end