Rails render turbo_stream 问题

zhugexinxin · 2023年05月19日 · 最后由 zhugexinxin 回复于 2023年05月19日 · 273 次阅读

首先我不用 respond_to

路径 views/share/notice.turbo_stream.erb

尝试了以下写法

render turbo_stream: turbo_stream.replace(
  'flash',
  template: 'share/notice.turbo_stream',
)
render template: "share/notice.turbo_stream", formats: [:turbo_stream]

全部是显示

也尝试过 partial 将文件改成 views/share/_notice.turbo_stream.erb

还是一样说找不到模版

参数是 partial 不是 template

render turbo_stream: turbo_stream.replace(
  'flash',
  partial: 'share/notice'
)
Rei 回复

partial 一开始我是用这个的,这样也错,后来我把_notice.turbo_stream.erb 改成了_notice.erb,居然好了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号