My use case is pretty simple: click a link to GET
a TURBO_STREAM
response to display on the page.
However, instead of a TURBO_STREAM
template being returned, Rails is returning an entire page.
To illustrate, I’ve included the relevant parts of the log output below.
1 15:06:49 web.1 | Started GET "/o/4/settings/member/3/edit" for ::1 at 2022-11-24 15:06:49 -0500
2 15:06:49 web.1 | Processing by Tenant::SettingsController#edit_member as TURBO_STREAM
3 15:06:49 web.1 | Parameters: {"organization_id"=>"4", "user_id"=>"3"}
4 ...
5 15:06:49 web.1 | Rendering layout layouts/application.haml
6 15:06:49 web.1 | Rendering tenant/settings/edit_member.turbo_stream.erb within layouts/application
7 15:06:49 web.1 | Rendered tenant/settings/_member_form.html.erb (Duration: 0.0ms | Allocations: 12)
8 15:06:49 web.1 | Rendered tenant/settings/edit_member.turbo_stream.erb within layouts/application (Duration: 0.3ms | Allocations: 247)
9 ...
10 Renders a bunch of things from the layout
11 ...
12 15:06:49 web.1 | Rendered layout layouts/application.haml (Duration: 3.2ms | Allocations: 2533)
13 15:06:49 web.1 | Completed 200 OK in 11ms (Views: 3.5ms | ActiveRecord: 1.2ms | Allocations: 6348)
You can see that on Line 2, the request is being processed as a TURBO_STREAM
request (as expected), and the TURBO_STREAM
response is within edit_member_form.html.erb
(Line 6).
However, as you can also see on Line 5, Rails is rendering the response within the default application layout. As a result, the response is not rendered on the screen.
Code
link
How this request is made is via a link with the following data
attributes:
data: { action: "click->modals--slideover#open", turbo_stream: "" }
Here is the full HTML code of the link:
<%= link_to tenant_settings_edit_member_path(current_organization, member.id), data: { action: "click->modals~slideover#open", turbo_stream: "" }, class: "text-indigo-600 hover:text-indigo-900" do %>
Edit<span class="sr-only">, <%= user_full_name(member) %></span>
<% end %>
With data-turbo-stream
set to ""
, my understanding is that the request should be handled as a TURBO_STREAM
, which it is as seen on Line #2 in the log.
edit_member.turbo_stream.erb
<%= turbo_stream.update "slideover-title", "Edit Member" %>
<%= turbo_stream.update "slideover-body", partial: "member_form", locals: { membership: @membership } %>
Tenant::SettingsController#edit_member
def edit_member
@membership = ...
end