ruby-on-rails - Turbo_stream 格式不再发送
问题描述
我们目前正在努力将我们的网络应用搜索引擎从 Stimulus 更改为 Turbo。
然而,我们不断从我们的脚本中收到一个 HTML 请求而不是 Turbo 请求,并出现错误:“</p>
ActionController::UnknownFormat “.
Trying to force the request into the Turbo format give the following error :
“ ActionController::UnknownFormat - SearchController#search is missing a template for this request format and variant.
request.formats: ["text/html"]
request.variant: []: “
我们使用的是 7.0.0-beta.5 Turbo 版本。
看法
<h1>All Apps</h1>
<%= turbo_frame_tag "record" do %>
<%= form_with url: "/search", method: :get , data: { controller: "search" } do |form| %>
<%= form.text_field :search , data: { action: "input->search#findResults" } %>
<% end %>
<% end %>
<%= turbo_frame_tag "apps" do %>
<ul>
<% @apps.each do |app| %>
<%= content_tag :li, app.name %>
<% end %>
</ul>
<% end %>
<turbo-stream action="update" target="apps">
<template>
<ul>
<% @apps.each do |app| %>
<%= content_tag :li, app.name %>
<% end %>
</ul>
</template>
</turbo-stream>
class SearchController < ApplicationController
def search
@apps = ItunesConnect::App.where("name like ?", "#{params[:search]}%")
respond_to do |format|
format.turbo_stream
#format.html { redirect_to root_url(search: params[:search]) } #for testing
end
end
end
有什么建议吗?
解决方案
只是遇到了同样的问题:form withmethod: :get
不发送带有TURBO_STREAM
格式的请求(它是HTML
)。
艾丹的回答几乎是正确的——format: :turbo_stream
应该明确说明。它不应该是参数的散列元素,而是 URL 的参数,如下所示:
<%= form_with URL: search_path(format: :turbo_stream), method: :get , data: { controller: "search" } do |form| %>
推荐阅读
- react-native - 如何使用 React 原生测试库写出功能组件的方法
- android - 在 Android Studio 中如何让图像在 FloatingActionButton 中心
- android - 如何在 GridLayout 中均匀分布显示 XML 形状的子项(最大可能大小)?
- html - 为什么jQuery将单选按钮的值返回为“ON”?如何纠正它?
- sql - 如何使用 Django ORM 从三个连接的模型中进行这个非常复杂的查询?
- regex - 正则表达式删除引号之外的所有字母实例
- linux - 如何制作 usbmon 日志文件 (*.mon)?
- python-3.x - 如何使用 UUID PrimaryKeyRelatedField 创建嵌套的 DRF 序列化程序?
- ruby-on-rails - Rails 6如何装饰application.html.erb
- python - 如何通过pygments(使用pygount)分析源代码并获得SUM