【发布时间】:2018-08-13 19:38:20
【问题描述】:
我正在开发一个平台,他们要求我集成 Pundit gem。创建策略时,我意识到许多方法具有相同的访问控制策略。 示例:
Action1: Only accessible by the administrator or owner of the resource
Action2: Only accessible by the administrator or owner of the resource
Action3: Only accessible by the administrator or owner of the resource
.
.
.
然后我想通过以下方式创建动态方法
[: Action1 ?,: Action2? ,: Action3?].each do |meth|
define_method(meth){@current_user.admin? or @current_user.owner_resource?}
end
但我有一个问题: Ruby on Rails 是在运行时还是在编译时执行方法? 创建动态方法是最优的还是以静态方式分别创建 3 个方法更好?
谢谢!!!
【问题讨论】:
标签: ruby-on-rails ruby compilation execution pundit