Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Devise + Authority Redirect to root is not authorized else ask using to login first. auth_current_user is used in place of current_user for authority to prevent a "No Method found on nil" error.
class ApplicationController < ActionController::Base
[...]
def authority_forbidden(error)
Authority.logger.warn(error.message)
if user_signed_in?
flash[:alert] = "Not authorized to view this page"
session[:user_return_to] = nil
redirect_to root_url
else
flash[:alert] = "You must first login to view this page"
session[:user_return_to] = request.url
redirect_to new_user_session_path
end
end
def auth_current_user
current_user || User.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.