我对 Rails 很陌生,并且对以下策略有疑问(使用Pundit):我想比较两个对象:@record
and @foo
,如您在此处看到的:
class BarPolicy < ApplicationPolicy
def show?
@record.foo_id == @foo
end
end
我没有找到将第二个参数传递给权威方法(@foo)的好方法。
我想做类似的事情:
class BarsController < ApplicationController
def test
authorize bar, @foo, :show? # Throws ArgumentError
...
end
end
但是 Pundit 授权方法只允许两个参数。有没有办法解决这个问题?
谢谢!