我似乎无法获得正确格式的数据返回到浏览器进行涡轮处理。
app/views/the_form.html.erb
<%= turbo_frame_tag "dog_quick_search" do %>
<% form_tag quick_search_via_form_dogs_path(format: :turbo_stream) do %>
blah
blah
<%= submit_tag('Go', class: 'btn-warning') %>
<% end %>
字符串
app/controllers/dogs_controller.rb
def quick_search_via_form
do stuff...
render 'xxxx'
end
型
app/views/dogs/xxxx.
<%= turbo_frame_tag "dog_quick_search" do %>
Bring back ujs
<% end %>
型
基于xxxx的文件扩展名,我得到:
xxxx.html.erb:
ActionView::MissingTemplate (Missing template dogs/xxxx, application/xxxx with {:locale=>[:en], :formats=>[:turbo_stream], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.
型
xxx.erb:
The contents of xxxx.erb replace the entire webpage in the browser
型
xxx.turbo-stream.html.erb
ActionView::MissingTemplate (Missing template dogs/xxxx, application/xxxx with {:locale=>[:en], :formats=>[:turbo_stream], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.
型
从对Turbo的阅读来看,似乎我所要做的就是在源代码和渲染模板中设置匹配的turbo-frame id,并使用通常的.html.erb扩展名,它将用返回的内容替换turbo-frame。由于我无法返回.html.erb模板,我想知道这是否是问题所在,但无法看到如何阻止无法找到该特定模板的错误。
更新:
通过向render指令添加显式格式,它可以工作:
render 'xxxx' formats: :html
型
老实说,我不明白这一点--如果模板有扩展名.html.erb,那肯定会告诉rails它是一个html模板,就像它在以前的rails版本中所做的那样?
2条答案
按热度按时间q3qa4bjr1#
我只需要找到匹配的涡轮帧ID
这正是你需要做的,但你可能想让你的表单在框架之外:
z9ju0rcb2#
解决了
问题被确定为表单提交未被Turbo拦截。
这是因为需要通过运行
字符串
现在表单以TURBO-STREAM的形式提交。标签内容不会被替换,但这是明天的问题!