我想知道在我的应用程序中构建身份验证/授权的最佳方式。我想要拥有
许多公司帐户,可能使用子域
账户有很多用户
并且用户只能访问由他们自己或具有相同帐户的其他用户创建的记录。
我所做的研究提供了许多混合 n' 匹配的想法,用于以奇怪而美妙的方式组合 devise/cancan/authlogic,但我还没有找到任何东西可以告诉我限制用户访问数据的最佳方法在同一个模型中。
例如:
账户 1:欧亚大陆
用户 1:鲍勃
用户 2:吉姆
账号2:东亚
用户 1:戴夫
用户 2:艾伦
isbn 1: account_id 为 1
ISBN 2:account_id 为 2
我如何确保 Bob 无法访问或破坏 Isbn 2?
///更新 当然,现在我已经发布了这个,我的 google fu 已经启动,我已经找到了 RyanB 的自述文件 CanCan 2.0 ,这看起来很完美:
>资源
What if you need to change authorization based on a model's attributes? You can do so by passing a hash of conditions as the last argument to can. For example, if you want to only allow one to access projects which he owns you can set the :user_id option.
最佳答案
我建议使用 CanCan进行授权。
你的能力模型看起来像
can :manage, :isbn do |isbn|
isbn.account == current_user.account
end
然后你可以像那样使用条件语句吗? :manage, @post
在你的 Controller/Views 中。
关于ruby-on-rails - Rails 3 公司帐户有很多用户,限制对数据的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6655275/