2

レール (およびデバイス) で構築された単純な掲示板システムがあります。

システムに cancan を追加したいのですが、いくつかのルールを定義するのに問題があります。

つまり、私のアプリケーションには User モデル、Forum モデル、および ForumModerationModel があります。コード (簡略化):

class User < ActiveRecord::Base
  has_many :forum_moderations, dependent: :destroy, foreign_key: 'moderator_id'
  has_many :moderated_forums, through: :forum_moderations, source: 'moderated_forum'

class Forum < ActiveRecord::Base
  has_many :forum_moderations, dependent: :destroy

class ForumModeration < ActiveRecord::Base
  belongs_to :moderated_forum, class_name: 'Forum'
  belongs_to :moderator, class_name: 'User'

  validates_uniqueness_of :moderator_id, :scope => [:moderated_forum_id]
end

ご覧のとおり、ユーザーはNフォーラムをモデレートでき、フォーラムはユーザーがモデレートできNます。私の問題は次のとおりです。

:manageユーザーがこれらのモデルに従って特定のフォーラムのみを許可することを cancan に定義するにはどうすればよいですか?

この記事を読みました: https://github.com/ryanb/cancan/wiki/Defining-Abilities

しかし、私の User モデルにはこの目的で使用できる列がないため、行き詰まっています。

4

1 に答える 1