【问题标题】:Database help trying to get Functions from a group through users数据库帮助尝试通过用户从组中获取函数
【发布时间】:2011-07-11 09:33:10
【问题描述】:

我需要检查一个用户是否是一个组的一部分,该组具有允许他们访问用户管理页面的功能。我目前拥有的是

def user_managment
      # If they are in group 1              AND user has function id 1 (user management)
      if current_user.group_ids.include?(1) && current_user.function_ids.include?(1)#&& group.function_ids.include?(1)
      flash[:error] = "You have access to user management!"
      else
        flash[:error] = "You have DO NOT access to user management!"
      end

      if current_user.group_ids.include?(1) && group_ids(1).function_ids.include?(1)
        flash[:error] = "Test"
      end
    end

我不确定如何从用户控制器的表中检查他们是否有字符串用户管理有人可以帮忙吗?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 rubygems ruby-on-rails-plugins


    【解决方案1】:

    你这里说的是门禁控制,请please,停下你正在做的事情,看看one of the many, excellent authorization/ACL gems out there。例如,使用acl9,您可以编写一些更易于理解和表达的代码,例如:

    access_control do
      allow :manager, :of => User, :to => :user_management
    end
    

    自己滚动这些东西是一个糟糕的举动,你最终会在你的应用程序中交织出许多杂乱无章的代码,非常难以维护,并且无法确保它总是在做你需要做的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 2020-03-21
      • 1970-01-01
      • 2019-12-27
      相关资源
      最近更新 更多