Class: Transit::Controller::Responder

Inherits:
ActionController::Responder
  • Object
show all
Includes:
Responders::FlashResponder
Defined in:
lib/transit/controller/responder.rb

Constant Summary collapse

@@flash_keys =
[ :success, :error ]

Instance Method Summary collapse

Constructor Details

#initialize(controller, resources, options = {}) ⇒ Responder

Returns a new instance of Responder.



14
15
16
17
18
19
20
# File 'lib/transit/controller/responder.rb', line 14

def initialize(controller, resources, options={})
  super
  @flash     = options.delete(:flash)
  @notice    = options.delete(:success)
  @alert     = options.delete(:error)
  @flash_now = options.delete(:flash_now)
end

Instance Method Details

#to_jsObject



22
23
24
25
26
27
28
29
30
# File 'lib/transit/controller/responder.rb', line 22

def to_js
  if set_flash_message?
    set_flash_message! 
    header_hash = {}
    controller.flash.each{ |key, value| header_hash.merge!(key => value) }
    controller.response['X-Flash-Messages'] = header_hash.to_json
  end      
  defined?(super) ? super : to_format
end