I have a form that appears in two places pointing to the same controller. Before hotwire that wasn’t a problem because after submitting it would redirect to the correct page in both cases. Now, with hotwire, it needs to update one page, one case, and redirect in the other case.
The controller action looks something like this, simplified:
class InvitationsController < ApplicationController
def create
@invitation = Invitation.new(invitation_params)
@invitation.requester = current_user
if @invitation.save
respond_to do |format|
format.turbo_stream
format.html { redirect_to invitations_url, notice: "#{@invitation.name} was invited." }
end
end
end
create.turbo_streams.erb looks like this:
<%= turbo_stream.append "invitations", @invitation %>
and invitations/index.html.erb as a turbo-frame with id “invitations”.
The problem is that there’s another page that also calls invitations/create and in that case, what should happen is it should redirect to invitations_url. How should that happen?