Class: Weft::Redirect
- Inherits:
-
Object
- Object
- Weft::Redirect
- Defined in:
- lib/weft/redirect.rb
Overview
Value object returned from action callables to trigger navigation instead of re-rendering. The Router detects Redirect returns and sends HX-Redirect (htmx) or 302 (traditional form).
Preferred form accepts a Page subclass:
Weft::Redirect.to(OrderDetailPage, order_id: order.id)
String path fallback:
Weft::Redirect.to("/orders/#{order.id}")
Convenience wrapper:
Weft.redirect(OrderDetailPage, order_id: order.id)
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
-
.to(target, **attrs) ⇒ Object
Primary constructor.
Instance Method Summary collapse
-
#initialize(target, **attrs) ⇒ Redirect
constructor
private
Use Redirect.to (or redirect) —
newis private. -
#url ⇒ Object
Resolve the redirect URL.
Constructor Details
#initialize(target, **attrs) ⇒ Redirect
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use to (or Weft.redirect) — new is private.
21 22 23 24 |
# File 'lib/weft/redirect.rb', line 21 def initialize(target, **attrs) @target = target @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
17 18 19 |
# File 'lib/weft/redirect.rb', line 17 def attrs @attrs end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
17 18 19 |
# File 'lib/weft/redirect.rb', line 17 def target @target end |
Class Method Details
.to(target, **attrs) ⇒ Object
Primary constructor.
39 40 41 |
# File 'lib/weft/redirect.rb', line 39 def self.to(target, **attrs) new(target, **attrs) end |
Instance Method Details
#url ⇒ Object
Resolve the redirect URL. Page targets: interpolate attrs into page_path pattern. String targets: use as-is.
29 30 31 32 33 34 35 36 |
# File 'lib/weft/redirect.rb', line 29 def url case @target when String @target else @target.resolve_page_path(@attrs) end end |