我正try 通过表单执行POST请求,但我不想执行turbo_stream请求;我想执行一个HTML请求.
我try 将data-turbo-stream="False"放在表单标记中,但它一直在执行turbo流请求.
<%= form_with(model: book, data: {turbo_stream: false}) do |form| %>
这是生成的HTML语言:
<form data-turbo-stream="false" action="/books" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="t1PouR2NA4bSleg8OBSRQhvAP1DTSmCkchiTf4aqUIWuPJjG9pJk3J58Z25o9-S2ZXhqFwaUSTfWFn0LvQZF3Q" autocomplete="off">
Ruby version:卢比3.2.2(2023-03-30修订版e51014f9c0)[x64-mingw-ucrt]
Rails version:轨7.0.8
谢谢!!
这是我的Create方法.它始终以TRUBO_STREAM格式响应:
# POST /books or /books.json
def create
@book = Book.new(book_params)
respond_to do |format|
if @book.save
format.html { redirect_to book_url(@book), notice: "Book was successfully created." }
format.turbo_stream
format.json { render :show, status: :created, location: @book }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @book.errors, status: :unprocessable_entity }
end
end
end