Skip to content
kristianmandrup edited this page Jan 10, 2011 · 1 revision

The Group API allows multiple roles to be grouped.

Example:

Say you have the admin roles:

  • Admin
  • Super admin

And the customer roles

  • Individual customer
  • Company customer

You might want to group them like this:

  User.add_role_group :customers => [:individual_customer, :company_customer]
  User.add_role_group :admins => [:admin, :super_admin]  

Then you can handle any user with regards to his/her role group relationship like this:

  # do this only for users in the admin role group (user has either :admin or :super_admin role) 
  current_user.is_in_group? :admins do
    ...
  end

In your views you can guard view code with Role Group conditions:

  # do this only for users in the admin role group (user has either :admin or :super_admin role) 
  for_user_in_group :customers do
    ...
  end

  # Cream 0.8.9 (edge)
  not_for_user_in_group :admins do
    ...
  end