如何通过 iframe 将我的 Rails 应用程序嵌入到另一个网站?
它可以很好地与 RoR 3 配合使用,但不能与 RoR 4 配合使用:
<iframe src="http://myrailsapp.com/" width="100%" height="50" id="rails_iframe">error!</iframe>
我尝试在 Controller 中使用 verify_authenticity_token
和 protect_from_forgery
选项...似乎是其他东西(但我不确定)。
更新。例子: http://jsfiddle.net/zP329/
最佳答案
这与 Rails 4 默认启用附加安全协议(protocol)有关:http://weblog.rubyonrails.org/2013/2/25/Rails-4-0-beta1/
破坏远程站点上 iFrame 的设置是 X-Frame-Options。默认情况下,它设置为 SAMEORIGIN,这可以防止跨域加载内容:
config.action_dispatch.default_headers = {
'X-Frame-Options' => 'SAMEORIGIN'
}
您可以在此处了解新的默认 header : http://edgeguides.rubyonrails.org/security.html#default-headers
为了允许 iFrame 跨域工作,您可以更改默认 header 以允许 X-Frame 跨域。
config.action_dispatch.default_headers = {
'X-Frame-Options' => 'ALLOWALL'
}
关于ruby-on-rails - Ruby on Rails 4 应用程序无法在 iframe 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16561066/