Rails render turbo_stream 问题

zhugexinxin · May 19, 2023 · Last by zhugexinxin replied at May 19, 2023 · 278 hits

首先我不用 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'
)
Reply to Rei

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

You need to Sign in before reply, if you don't have an account, please Sign up first.