In a perfect world I would like to do something like this:
def user_not_authorized
respond_to do |format|
format.html do
flash[:alert] = "You are not authorized to perform this action."
redirect_back(fallback_location: root_path)
end
format.turbo_stream do
flash.now[:alert] = "You are not authorized to perform this action."
turbo_stream.prepend "flash", partial: "shared/flash"
end
end
end
And then if someone tried to perform an action they can't do, they would get a flash message on their current page / frame without a redirect.
With the above code using Pundit v2.2.0, on authorization failure no alert message gets shown and no redirect happens. The request gets executed as the html format which I verified by printing a message to the terminal in that block.
As is Pundit doesn’t send the request as a turbo_stream so that format never gets a chance to execute. Is there a current workaround or official plans to support Hotwire Turbo Frames and Steams given it's a Rails 7 default?
Thanks!
In a perfect world I would like to do something like this:
And then if someone tried to perform an action they can't do, they would get a flash message on their current page / frame without a redirect.
With the above code using Pundit v2.2.0, on authorization failure no alert message gets shown and no redirect happens. The request gets executed as the
htmlformat which I verified by printing a message to the terminal in that block.As is Pundit doesn’t send the request as a
turbo_streamso that format never gets a chance to execute. Is there a current workaround or official plans to support Hotwire Turbo Frames and Steams given it's a Rails 7 default?Thanks!