Rails 4 のデフォルトのX-Frame-OptionsHTTP ヘッダー値が追加されましSAMEORIGINた。これはセキュリティに適していactionますが、 で を呼び出したい場合はiframe、次のようにすることができます。
すべてのオリジンを許可するには:
class MyController < ApplicationController
def iframe_action
response.headers.delete "X-Frame-Options"
render_something
end
end
特定のオリジンを許可するには:
class MyController < ApplicationController
def iframe_action
response.headers["X-FRAME-OPTIONS"] = "ALLOW-FROM http://some-origin.com"
render_something
end
end
:after_filter を使用
で を複数使用する必要がある場合は、メソッドを作成しactionてiframeで呼び出すことをお勧めします:after_filter。
class ApplicationController < ActionController::Base
private
def allow_iframe
response.headers.delete "X-Frame-Options"
end
end
次のようにコントローラーで使用します。
class MyController < ApplicationController
after_filter :allow_iframe, only: [:basic_embed, :awesome_embed]
def basic_embed
render_something
end
def awesome_embed
render_something
end
# Other Actions...
end
経由: Rails 4: 特定のアクションを iframe として埋め込む