1

アプリケーションに現在のデータベースestructureがあります。

Publisher has_many videos, has_many users
Video      belongs_to publisher
User       belongs_to publisher

サイト運営者に基づいてユーザーに権限を付与できるようにしたいのですが、実際に編集されるオブジェクトはビデオオブジェクトです。

つまり、ユーザーXはパブリッシャー1と2のビデオを編集できますが、ユーザーYはパブリッシャー2と3のビデオのみを編集できます。これは、CanCan、Devise、Rolifyのコンボで実行できると確信しています。

誰かが私をここで正しい方向に向けることができますか?

4

1 に答える 1

1

返信が遅れて申し訳ありません。これで問題が解決したことを願っていますが、解決策を提供します。

あなたの CanCan 能力には、次のようなものがあります。

def initialize(current_user) 
  current_user ||= User.new

  can :update, Video do |video|
    current_user.publisher_list.contains? video.publisher
  end
end

上記のコードは、user.publisher_list がユーザーが変更できる発行者のリストを返す場合に機能します。あなたもできると思います:

def initialize(current_user)
  current_user ||= User.new

  can :update, Video, publisher: {id: current_user.publisher_list}
end
于 2012-08-13T15:56:31.603 に答える