Skip to content

Instantly share code, notes, and snippets.

@sideshowbandana
Created June 28, 2019 10:44
Show Gist options
  • Select an option

  • Save sideshowbandana/ecf06bb2249df00afe7b53a13acde6e0 to your computer and use it in GitHub Desktop.

Select an option

Save sideshowbandana/ecf06bb2249df00afe7b53a13acde6e0 to your computer and use it in GitHub Desktop.
def current_ability
@current_ability ||= Abilities::Factory.ability_for(self.class, current_user)
end
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.jsonapi { render jsonapi: { meta: { error: exception.message } }, status: :forbidden }
format.json { head :forbidden, content_type: 'text/html' }
format.html { redirect_to main_app.root_url, notice: exception.message }
format.js { head :forbidden, content_type: 'text/html' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment