diff --git a/src/marten_turbo/turbo_stream.cr b/src/marten_turbo/turbo_stream.cr index 0895dd5..e589659 100644 --- a/src/marten_turbo/turbo_stream.cr +++ b/src/marten_turbo/turbo_stream.cr @@ -28,7 +28,8 @@ module MartenTurbo # stream = MartenTurbo::TurboStream.new # stream.action("append", "messages", "
New Message
") # ``` - def action(action, target_id : String, content) + def action(action, target : String | Marten::Model, content) + target_id = target.is_a?(String) ? target : dom_id(target.as(Marten::Model)) @streams << <<-TURBO_STREAM_TAG #{render_template_tag(content)} @@ -42,17 +43,10 @@ module MartenTurbo # # ``` # stream = MartenTurbo::TurboStream.new - # stream.replace("append", Message.get(pk: 1), "
Updated Message
") + # stream.replace("append", Message.get!(pk: 1), "
Updated Message
") # ``` def action(action, target : Marten::Model, content) - target_id = dom_id(target) - @streams << <<-TURBO_STREAM_TAG - - #{render_template_tag(content)} - - TURBO_STREAM_TAG - - self + action(action, dom_id(target), content) end {% for action in ACTIONS %}