、、を使用したRubyonRailsアプリがusers
ありarticles
ますcollaborations
。関係は次のとおりです。
User has_many :articles
User has_many :collaborations
Article belongs_to :users
Article has_many :collaborations
# Collaboration has collaboration.id collaboration.user_id and collaboration.article_id.
Collaboration belongs_to :users
Collaboration belongs_to :articles
コラボレーションを行うことで、ユーザーと記事の両方に正常にアクセスできるので、アプリですべてが正しく設定されていると思います。質問してください。
の役割でCanCanを使用してい:admin
ます。:admin
基本的には、投稿とコラボレーションを作成できるようにしたいだけで、それも正しく機能しています。ability.rb
問題は...管理者ではないユーザーがコラボレーションの一部である記事で引き続きコラボレーションできるように、その役割をファイルに書き込むにはどうすればよいですか?」
- ユーザーA(管理者)がArticleXを作成します
- ユーザーAは、ユーザーBとの記事Xに関するコラボレーションを作成します
- ユーザーBはログインしますが、ArticleXの編集と更新のみが可能です。
どのようにそれを書くべきですかability.rb
。「管理者ではないユーザーは、その記事のコラボレーションの一部である記事を管理できます。」と言いたいのです。
冗長になってすみません、まだ私のコーヒーを飲んでいません:)。これが私のability.rb
です。
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
if user.role == "admin"
can :manage, :all
else
can :read, Article
# this is where I want to say: can :manage if part of collaboration for article
end
end
end