質問

宣言承認にはほとんど問題がありません。has_and_belongs_to_many協会を備えたユーザーとロールモデルがあります。

My Authorization_Rules.rb に記載された役割を作成しました。

ロールモデレータを持つユーザーが、モデレータロールが割り当てられているユーザーのみを取得することができますか。 - > user.with_permission_to(:index)

私はそれがそのように可能だと思った:

role :moderator do
  has_permission_on :users, :to => :index do
    if_attribute :roles => contains { ????? }
  end
end
.

私はそれが役立つと思ったので私のユーザモデルにnamed_scopeを作成しました...

class User
  has_and_belongs_to_many :roles
  named_scope :by_role, lambda { |role|
    {
      :include => :roles,
      :conditions => {"roles.name" => role}
    }
  }
end
.

誰もが宣言的なものでこれを行うことが可能であるかどうかを知っていますか?

あなたの助けをありがとう!

役に立ちましたか?

解決

I did something similar in one of my projects but found dec_auth really confusing at the time. I think this is what you need to do:

authorization_rules.rb:

role :moderator do
  has_permission_on :users, :to => :index
end

User Model:

class User < ActiveRecord::Base
  using_access_control
end

Controller:

@users = User.with_permissions_to(:index)

Let me know if that doesn't work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top