views:

82

answers:

2

Hi,

I am using Acl9 to manage the roles and I want to hide the checkbox usertype if the user has the role :customer and show it if the role is :manager. I want that just the :manager can edit all the fields and some for the :customer.

Thank you for your help!

<h1>Editing user</h1>

<% form_for(@user) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :usertype %><br />
    <%= f.check_box :usertype %>
  </p>
  <p>
    <%= f.label :surname %><br />
    <%= f.text_field :surname %>
  </p>
  <p>
    <%= f.label :firstname %><br />
    <%= f.text_field :firstname %>
  </p>
  <p>
    <%= f.label :phone %><br />
    <%= f.text_field :phone %>
  </p>
  <p>
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </p>
  <p>
    <%= f.label :registrationdate %><br />
    <%= f.datetime_select :registrationdate %>
  </p>
  <p>
    <%= f.label :login %><br />
    <%= f.text_field :login %>
  </p>
  <p>
    <%= f.label :password %><br />
    <%= f.text_field :password %>
  </p>
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>

<%= link_to 'Show', @user %>
<%= link_to 'Back', users_path %>
+1  A: 

According to the Acl9 documentation, you should be able to do something like this:

<% if @user.has_role?(:manager, nil) %> 
  <p>
    <%= f.label :usertype %><br />
    <%= f.check_box :usertype %>
  </p>
<% end %>
John Topley
Thank you very much!
Michaël
A: 

You can also do think like that:

..in your application_helper.rb

module ApplicationHelper
  include Acl9Helpers
end

..and in your views, something like that

<% show_to(:admin) do %>
  The content to show
<% end %>
Andrey Viana