[英]Show or hide fields depending on the Acl9 role - Ruby on Rails
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. 我正在使用Acl9来管理角色,并且如果用户具有:customer角色,我想隐藏该复选框的用户类型,如果角色是:manager,则要显示它。 I want that just the :manager can edit all the fields and some for the :customer. 我希望仅:manager可以编辑所有字段,并且可以编辑: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 %>
You can also do think like that: 您也可以这样想:
..in your application_helper.rb ..在您的application_helper.rb中
module ApplicationHelper
include Acl9Helpers
end
..and in your views, something like that ..在您看来,类似的东西
<% show_to(:admin) do %>
The content to show
<% end %>
According to the Acl9 documentation , you should be able to do something like this: 根据Acl9文档 ,您应该能够执行以下操作:
<% if @user.has_role?(:manager, nil) %>
<p>
<%= f.label :usertype %><br />
<%= f.check_box :usertype %>
</p>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.