简体   繁体   English

Rails权限明显不一致

[英]Rails authority apparent inconsistency

I am using the gems authority and rolify to manage user permissions on a set of subjects. 我正在使用gems权限并进行漫游以管理一组主题上的用户权限。 Each subject can be seen by a user only if the user has the :admin role for that subject. 仅当用户具有该主题的:admin角色时,该用户才能看到每个主题。 Code in the view: 视图中的代码:

   <% if (current_user.has_role? :admin, @subject) %>
        ADMIN
    <% end %>

    <% if @subject.readable_by?(current_user)%>

    #some other code

    <% end %>

Code in the authorizer: 授权者中的代码:

class SubjectAuthorizer < ApplicationAuthorizer
  # can the user view the subject?
  def self.readable_by?(user)
    user.has_role? :admin, @subject
  end

end

My problem is that the ADMIN part is displayed, but not the rest of the page. 我的问题是显示的是ADMIN部分,而不显示页面的其余部分。 However, the two if conditions should have the same truth value. 但是,两个if条件应具有相同的真值。 Can anyone spot a mistake? 谁能发现一个错误?

@subject is not available in the Authorizer. @subject在授权者中不可用。 You need to use resource instead. 您需要使用resource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM