Module: ModalStack::ControllerExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/modal_stack/controller_extensions.rb
Instance Method Summary collapse
-
#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_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).
44 45 46 47 48 |
# File 'lib/modal_stack/controller_extensions.rb', line 44 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
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/modal_stack/controller_extensions.rb', line 60 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 |