Module: ModalStack::ControllerExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/modal_stack/controller_extensions.rb
Instance Method Summary collapse
-
#modal_stack_config ⇒ Object
Request-scoped accessor for ‘ModalStack.configuration`.
-
#modal_stack_request? ⇒ Boolean
True when the current request was issued by the modal_stack JS runtime (signaled by the X-Modal-Stack-Request header on the fetch).
-
#render_modal(template_or_options = nil, **options) ⇒ Object
Convenience for re-rendering inside the modal layout, e.g.
Instance Method Details
#modal_stack_config ⇒ Object
Request-scoped accessor for ‘ModalStack.configuration`. Memoized so helpers that read several config values per render hit the global singleton once instead of N times.
45 46 47 |
# File 'lib/modal_stack/controller_extensions.rb', line 45 def modal_stack_config @modal_stack_config ||= ModalStack.configuration end |
#modal_stack_request? ⇒ Boolean
True when the current request was issued by the modal_stack JS runtime (signaled by the X-Modal-Stack-Request header on the fetch).
51 52 53 54 55 |
# File 'lib/modal_stack/controller_extensions.rb', line 51 def modal_stack_request? return false unless respond_to?(:request) && request request.headers[ModalStack::REQUEST_HEADER] == "1" end |
#render_modal(template_or_options = nil, **options) ⇒ Object
Convenience for re-rendering inside the modal layout, e.g. after a validation failure on update:
def update
if @project.update(project_params)
redirect_to @project
else
render_modal :edit, status: :unprocessable_entity
end
end
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/modal_stack/controller_extensions.rb', line 67 def render_modal( = nil, **) render_args = if .is_a?(Hash) .merge() elsif { => true, ** } else end render_args[:layout] = "modal" unless render_args.key?(:layout) render(**render_args) end |