I am working on a simple authorization in a Rails 4 app. Each user has a role; then I set up pages they can access, for example:
AUTH_MODERATOR_DEFINITIONS = {"articles" => "index",
"readers" => "index"}
Then, in a controller action, I will call:
def index
check_permissions(current_admin)
...
end
And in the ApplicationController:
def check_permissions(current_admin)
if current_admin.role == 1 # for moderators
# find a pair key-vale AUTH_DISPATCHER_DEFINITIONS that matches `params[:controller]` and `params[:action]
else
redirect_to root_path, :alert => "No permission"
end
end
But how to search a hash according to key AND value?
Thank you in advance.