Skip to content

Instantly share code, notes, and snippets.

@technicalpickles
Forked from tcocca/gist:594209
Created September 23, 2010 20:29
Show Gist options
  • Save technicalpickles/594297 to your computer and use it in GitHub Desktop.
Save technicalpickles/594297 to your computer and use it in GitHub Desktop.
# match method names like
# logged_id_super_admin_or_admin?
# or
# logged_in_admin_or_lead?
def method_missing(method_name, *args)
if method_name.to_s.match(/^logged_in_(.*)?$/)
roles = $1.split('_or_')
return false unless logged_in? && current_user.company_id == current_company.id
roles.each do |role|
return false unless send("#{role}_role?")
end
return true
else
super
end
end
def super_admin_role?
current_user.super_admin?
end
def admin_role?
current_user.is_broker?
end
def lead_role?
current_user.is_lead?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment