we are currently working on changing our web app search engine from Stimulus to Turbo.
However, we keep getting an HTML request instead of a Turbo one from our script with the error : “
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: []: “
We are on the 7.0.0-beta.5 Turbo version.
View
<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
Any advises ?
I may have just had a similar problem. I think you need to specify
format: :turbo_stream
as one of your options toform_with
. In my case, I wanted to hit the HTML block but the form kept hitting turbo_stream instead.To be extra clear, this
becomes this