0

我想通过 iFrame 从任何域提供我的 Rails 应用程序视图。

在 Rails 4 中,可以防止来自其他域的 X-Frame,如下所述:http: //edgeguides.rubyonrails.org/security.html#default-headers

因此,解决方案是将其放在 application.rb 中:

config.action_dispatch.default_headers = {
  'X-Frame-Options' => 'ALLOWALL'
}

这在我的本地服务器和 Heroku 中都很有效。但是让 Web 应用程序的所有视图都暴露在任何域的 iframe 中调用。

我只想公开 iframe 视图。因此,我尝试仅在用于生成 iframe 视图的控件中配置标头,而不是以前的解决方案:

def iframe
  response.headers["X-Frame-Options"] = "ALLOWALL"

...

end

它在我的本地服务器上运行良好。但是当我将它上传到 Heroku 时它不起作用。

知道为什么第二种解决方案在 Heroku 中不起作用吗?

谢谢

4

1 回答 1

1

这个答案中得到提示,您可能希望在after_action回调中设置标题:

after_action :allow_iframe, only: :iframe

def iframe
  #your code
end

private

def allow_iframe
  response.headers['X-Frame-Options'] = "ALLOWALL"
end

after_action

于 2014-05-15T09:03:49.820 回答