跳至内容 跳至搜索
方法
P

实例公共方法

permissions_policy(**options, &block)

覆盖全局配置的 Feature-Policy 标头的部分

class PagesController < ApplicationController
  permissions_policy do |policy|
    policy.geolocation "https://example.com"
  end
end

选项可以类似于 before_action 传递。例如,传递 only: :index 以仅在索引操作中覆盖标头

class PagesController < ApplicationController
  permissions_policy(only: :index) do |policy|
    policy.camera :self
  end
end
# File actionpack/lib/action_controller/metal/permissions_policy.rb, line 26
def permissions_policy(**options, &block)
  before_action(options) do
    if block_given?
      policy = request.permissions_policy.clone
      instance_exec(policy, &block)
      request.permissions_policy = policy
    end
  end
end