Skip to content

User role and host helpers

pacoguzman edited this page Dec 25, 2010 · 2 revisions

Cream comes with a few helper methods to make it easy to act according to the role of the current user and the host IP address.

has_role?

if has_role? :admin
...
end

has_roles?

If the user has all the roles given, …

if has_roles? :editor, :admin
...
end

owner?

Tests if the #editor method on the @post object is the same as the current_user.

if owner? @post, :editor
...
end

Host helpers

Use these to act according to the user host IP address.

localhost?

if localhost?
...
end

publichost?

if publichost?
...
end