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_html ⇒ Object
- #to_js ⇒ Object
- #to_json ⇒ Object
Instance Method Details
#options ⇒ Object
12 13 14 15 16 17 |
# File 'lib/locomotive/action_controller/responder.rb', line 12 def membership = self.controller.send(:current_membership) policy = membership ? Pundit.policy(membership, resource) : nil super.merge(policy: policy) 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_html ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/locomotive/action_controller/responder.rb', line 19 def to_html add_authenticated_header if controller.request.headers['X-Flash'] == 'true' (:notice, true) { super } else super end end |
#to_js ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/locomotive/action_controller/responder.rb', line 29 def to_js add_authenticated_header if controller.request.headers['X-Flash'] == 'true' (:notice, true) { super } else super end end |
#to_json ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/locomotive/action_controller/responder.rb', line 39 def to_json add_authenticated_header if get? add_pagination_header if resource.respond_to?(:total_pages) 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 |