Hi,
I’m integrating Pundit into a project for authorization and its documentation suggests adding this to your project as a general fallback plan when authorization fails:
class ApplicationController < ActionController::Base
include Pundit::Authorization
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
private
def user_not_authorized
flash[:alert] = "You are not authorized to perform this action."
redirect_back(fallback_location: root_path)
end
end
This works great when you’re not dealing with Turbo Frames and Turbo Streams, but when inside of a Turbo Frame or using Turbo Streams I noticed that the flash message will never get shown. I’ve also tried using flash.now[:alert]
and it results in the same outcome of the flash message not being shown.
Any thoughts on how to workaround this without having to disable Turbo for these actions? In my exact use case I’m operating inside of a nested frame (think tabbed navigation and inside of each tab there’s fully self contained frames). Disabling frames and streams isn’t an option here.
Thanks!