0
私は認証のためにDeviseを使用しています& CanCanCan/Rolify for Authorization。Rails - CanCanCan、Rolify、Define - 関連モデルの能力の定義
私は、モデルのレコードを、作成したユーザーに、さまざまな関連付けによって制限したいと考えています。
I.e./sales/1は、販売を行っている組織に属しているユーザーのみが見ることができます。それに属しているユーザーに組織を制限
User
has_many :organisations
Organisation
belongs_to :user
has_many :sales
Sale
belongs_to :organisation
has_many :payments
Payment
belongs_to :sale
は前方にまっすぐです:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.has_role? :admin
can :manage, :all
elsif user.has_role? :standard
can [:create, :read, :update, :destroy], Organisation, :user_id => user.id
end
end
end
はどのように関連する販売、その後、関連する支払いのために同じことを達成することができますか?
can [:manage], Sale, ?
can [:manage], Payment, ?
注:Railsの5.0.0.1、Rubyの2.3.1
素晴らしい作品 - ありがとう –