```ruby
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  rescue_from CanCan::AccessDenied do |exception|
    # 'now' is required because else the flash doesn't desapear when page is
    # reloaded.
    flash.now[:alert] = exception.message
    respond_to do |format|
      format.html { redirect_to request.referrer || root_url }
      format.js   { render 'shared/unauthorized' }
    end
  end
end
```

Remove 'now' call from flash in rescue_from
user
```ruby
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  rescue_from CanCan::AccessDenied do |exception|
    flash[:warning] = exception.message
    respond_to do |format|
      format.html { redirect_to request.referer || root_url }
      format.js   { render 'shared/unauthorized' }
    end
  end
end
```
assistant