The best I can come up with is to use multiple can?
statements and raise AccessDenied
on failure. You also should avoid authorization checks against a model class, and instead authorize against a model instance. See CanCanCan - Common Mistakes.
user = User.new(...)
group = Group.new(...)
raise CanCan::AccessDenied.new(nil, :create, [user, group]) \
unless can?(:create, user) || can?(:create, group)
AccessDenied.new(nil, ..) -> nil
for the first argument result in the default error message.
See cancan/exceptions.
I'd probably move this into a helper to a method named def authorize create_group_or_user!
That said, maybe you are doing too much in this controller? Alternatively, you could make this controller redirect without authorization to the appropriate GroupController
or UserController
, and perform the appropriate authorization checks in those locations.
Alternate Option 2: Maybe use an accessible_by
restriction on the content, and don't call authorize!
at all.