I’m starting to migrate my Rails 6.1.3.2 app to use turbo instead of ujs. My app is using a namespace for an “admin” area for auth’d users to manage things as well as a frontend for someone navigating to the site to just view, here’s an example -
resources :event_attachments
namespace :admin do
resources :event_attachments
end
I’m struggling with why, when I make an update to an event_attachment, the turbo_stream is not being processed by the Admin::EventAttachmentsController, instead it’s being processed by EventAttachmentsController
Started PATCH "/event_attachments/25" for ::1 at 2022-01-03 22:18:53 -0500
Processing by EventAttachmentsController#update as TURBO_STREAM
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "event_attachment"=>{"title"=>"Test Name", "summary"=>"caption"}, "commit"=>"Save Changes", "id"=>"25"}
EventAttachment Load (1.1ms) SELECT `event_attachments`.* FROM `event_attachments` WHERE `event_attachments`.`id` = 25 LIMIT 1
↳ app/controllers/event_attachments_controller.rb:51:in `set_event_attachment'
Rendered event_attachments/_event_attachment.html.erb (Duration: 0.1ms | Allocations: 22)
[ActionCable] Broadcasting to event_attachments: "<turbo-stream action=\"update\" target=\"event_attachment_25\"><template><li id=\"event_attachment_25\">\n hello\n</li>\n</template></turbo-stream>"
Redirected to http://localhost:3000/event_attachments/25
Completed 302 Found in 4ms (ActiveRecord: 1.1ms | Allocations: 1640)
My Admin:EventAttachmentsController update action is as follows -
def update
if @event_attachment.update(event_attachment_params)
respond_to do |format|
format.turbo_stream do
render turbo_stream: [
turbo_stream.update("flash", partial: "shared/flash", locals: { notice: "Event image updated" }),
turbo_stream.replace(:event_attachments, partial: 'admin/pages/event_attachment', locals: { event_attachment: @event_attachment })
]
end
format.html do
redirect_to edit_admin_event_attachment_path(@event_attachment), notice: 'Event image updated'
end
end
else
render :edit, status: :unprocessable_entity
end
end
Any ideas?