-
Notifications
You must be signed in to change notification settings - Fork 17
Permission view block helpers
Cream comes with a set of view block helpers to make it easy to guard blocks of view logic and only execute that block for Users that match certain role criteria.
for_any_user :logged_in do
...
end
The valid options arguments are :signed_in_, :_logged_in, :signed_out, :logged_out and negations with prefix :not_xxxx
You can supply this as either a symbol or a hash (see below)
These argument options also apply for the not_for_any_user method
not_for_any_user :logged_in do
...
end
not_for_any_user :logged_out => true do
...
end
for_role :editor do
...
end
not_for_role :editor do
...
end
for_roles :editor, :admin do
...
end
not_for_roles :editor, :admin do
...
end
- for_user_in_group
- for_user_in_groups
- for_user_in_any_group
All with symmetric negation method using prefix: not_xxxx
for_user_in_group :admins do
...
end
for_user_in_any_group :admins, :editors do
...
end
not_for_user_in_any_group :publishers, :editors do
...
end
Cream also comes with some helpers
area_for_roles :editor, :admin do
...
end
Results in the following ouput if the user has any of the roles listed
<div class="special">
...
</div>
You can also specify a special class option.
area_for_roles :editor, :admin, :class => 'admin' do
...
end
Results in the following ouput if the user has any of the roles listed
<div class="admin">
...
</div>
There are also the methods: area_not_for_roles, area_for_role, area_not_for_role
Cream also comes with a few helpers to help guard certain areas for “development eyes only” (localhost) and others for public users.
Reverse of for_public
for_localhost do
...
end
Reverse of for_localhost
for_public do
...
end
Only shows it for request coming in from public users (non-localhost)