Rails 3 - how with declarative_authorization test, if user is admin?

309 Views Asked by At

In the documentation I found this part:

<% permitted_to? :create, :employees do %>
  <%= link_to 'New', new_employee_path %>
<% end %>

This is good, but I need to test, if the current user is admin, and if does, so then display some text... Something like

if admin?

I can get this information from associations, like:

if current_user.role == 0

but this is a bit dirty solution... support Declarative Authorization some cleaner and nicer way to do it?

1

There are 1 best solutions below

0
On

This is what I have been looking for:

if has_role?(:admin)
  ...
end