热线Turbo不能替代turbo-frame。

3

我有一个表单

<turbo-frame id="goals">
    <form action="/add_goal">
        <label for="goal_name">Goal Name</label>
        <input type="text" id="goal_name" name="goal_name" placeholder="Goal name..">
        <input type="submit" value="Add Goal">
    </form>
</turbo-frame>

我希望替换的内容。

作为回复,我发送303和"Location: /added_goal","/added_goal"返回:

<html>
<body>
<turbo-frame id="goals">
    OK!
</turbo-frame>
</body>
</html>

Turbo 设置 turbo-frame 的 src,但不替换内容。

1
发布你的控制器操作。 - ybakos
1个回答

0

您的服务器响应可能格式不正确。根据您的HTML,前端Turbo将期望类似以下内容:

<turbo-stream action="replace" target="goals">
  <template>
    <div>
      This div will replace the existing element with the DOM ID "goals".
    </div>
  </template>
</turbo-stream>

请参考Turbo文档,代码片段已从那里适配。

不确定您是否也遇到了这个问题,但您应该确保您的服务器响应的内容类型为text/vnd.turbo-stream。如果内容类型标头不正确,则HTML格式化正确也无济于事。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接