Class: Locomotive::ActionController::Responder
- Inherits:
-
ActionController::Responder
- Object
- ActionController::Responder
- Locomotive::ActionController::Responder
- Includes:
- Responders::FlashResponder
- Defined in:
- lib/locomotive/action_controller/responder.rb
Instance Method Summary collapse
- #options ⇒ Object
-
#set_flash_now? ⇒ Boolean
by default flash_now messages if the resource has errors.
- #to_json ⇒ Object
Instance Method Details
#options ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/locomotive/action_controller/responder.rb', line 12 def current_site = self.controller.send(:current_site) current_account = self.controller.send(:current_locomotive_account) ability = current_site.nil? || current_account.nil? ? nil : self.controller.send(:current_ability) super.merge({ :current_site => current_site, :current_account => current_account, :ability => ability }) end |
#set_flash_now? ⇒ Boolean
by default flash_now messages if the resource has errors
8 9 10 |
# File 'lib/locomotive/action_controller/responder.rb', line 8 def set_flash_now? super || has_errors? end |
#to_json ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/locomotive/action_controller/responder.rb', line 24 def to_json if get? display resource elsif has_errors? (:alert) do display resource.errors, :status => :unprocessable_entity end elsif post? in_header = controller.request.headers['X-Flash'] == 'true' (:notice, in_header) do display resource, :location => api_location end elsif put? do || display resource, :status => :ok, :location => api_location end elsif delete? do || display resource, :status => :ok, :location => api_location end elsif has_empty_resource_definition? display empty_resource, :status => :ok else do head :ok end end end |