根据 Acl9 角色显示或隐藏字段 - Ruby on Rails

发布于 2024-09-03 06:28:24 字数 1313 浏览 1 评论 0原文

我正在使用 Acl9 来管理角色,如果用户具有 :customer 角色,我想隐藏复选框用户类型,如果角色是 :manager,则显示它。我希望只有 :manager 可以编辑所有字段以及 :customer 的一些字段。

感谢您的帮助!

<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 %>

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 %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦一生花开无言 2024-09-10 06:28:24

您也可以这样想:

..在您的 application_helper.rb

module ApplicationHelper
  include Acl9Helpers
end

..在您的视图中,类似的东西

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

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 %>
勿忘心安 2024-09-10 06:28:24

根据 Acl9 文档,您应该能够执行类似的操作这:

<% if @user.has_role?(:manager, nil) %> 
  <p>
    <%= f.label :usertype %><br />
    <%= f.check_box :usertype %>
  </p>
<% end %>

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 %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文