Class: Motr::Controller::Responder
- Inherits:
-
ActionController::Responder
- Object
- ActionController::Responder
- Motr::Controller::Responder
- Defined in:
- lib/motr/controller/responder.rb
Overview
A custom responder which extends the default functionality of respond_with to handle more advanced javascript functionality, as well as flash messages.
Instance Method Summary collapse
-
#initialize(controller, resources, options = {}) ⇒ Responder
constructor
A new instance of Responder.
-
#to_js ⇒ Object
Override to_js to set a
X-Flash-Messages
header to be utilized by an ajax response.
Constructor Details
#initialize(controller, resources, options = {}) ⇒ Responder
Returns a new instance of Responder.
16 17 18 19 20 21 22 |
# File 'lib/motr/controller/responder.rb', line 16 def initialize(controller, resources, = {}) super flash = (format == :js) ? controller.flash : controller.flash.now [:success, :notice, :error].each do |key| flash[key] = .delete(key) if [key].present? end end |
Instance Method Details
#to_js ⇒ Object
Override to_js to set a X-Flash-Messages
header to be utilized by an ajax response.
28 29 30 31 32 |
# File 'lib/motr/controller/responder.rb', line 28 def to_js flash = controller.flash.now controller.response['X-Flash-Messages'] = flash.to_json if [:success, :notice, :error].detect{ |key| flash[key].present? } defined?(super) ? super : to_format end |