ActionController::UnknownFormat when using format.turbo_stream in Rails 7

Viewed 985

Hey I'm new to turbo_streams and am stuck on why I'm getting this error.

Properties partial:

<div id="properties"
     data-action="map-marker-clicked@window->@mapmarker#mapMarkerClicked"
     data-controller="mapmarker"
     data-mapmarker-target="properties_list">
  <%= "#{@properties.length} properties" %>

  <%= turbo_stream_from "properties" %>
  <%= turbo_frame_tag "properties" do %>
    <% @properties.each do |property| %>
      <%= render property %>
      <p>
        <%= link_to "View this property", property %>
      </p>
    <% end %>
  <% end %>
</div>

And my controller:

  def index
    @properties = location_search? ? Property::SearchByLocation.call(search_params[:value]) : Property.all

    @markers = Property::GenerateGoogleApiMapMarkers.call(property_or_properties: @properties)

    respond_to do |format|
      format.turbo_stream do
        render turbo_stream: turbo_stream.replace(@properties, partial: 'properties/properties')
      end
    end
  end

Bit more context: I plan to trigger this reload from a stimulus controller (when the user clicks a marker on the google maps I want to refresh the properties section with the coordinates of the marker as the way to organise the properties (the closest to the marker would show at the top).

I get the ActionController::UnknownFormat error when I go to http://localhost:3000/properties

enter image description here

1 Answers

You should add a default format.html action

Related