Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Role groups

kristianmandrup edited this page · 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
Something went wrong with that request. Please try again.