0

To work with iframe in rails4 is there any extra configuration needed to done?.

after upgrading to rails 4 iframe not working in my application which is used in so many places. any idea on this? i am using iframe with forms in rails4.also submiting the in jquery.

1
  • Why is not working? more info Commented Dec 5, 2013 at 18:03

2 Answers 2

4

Rails 4 added a default X-Frame-Options HTTP header value of SAMEORIGIN. This is good for security, but when you do want your action to be called in an iframe, you can do this:


To Allow all Origins:

class MyController < ApplicationController def iframe_action response.headers.delete "X-Frame-Options" render_something end end 

To Allow a Specific Origin:

class MyController < ApplicationController def iframe_action response.headers["X-FRAME-OPTIONS"] = "ALLOW-FROM http://some-origin.com" render_something end end 

Use :after_filter

When you need to use more than one of your action in an iframe, it's a good idea to make a method and call it with :after_filter:

class ApplicationController < ActionController::Base private def allow_iframe response.headers.delete "X-Frame-Options" end end 

Use it in your controllers like this:

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 

Via: Rails 4: let specific actions be embedded as iframes

Sign up to request clarification or add additional context in comments.

Comments

2

As already answered here: Ruby on rails 4 app does not work in iframe

There's a new default in Rails 4 which adds an header by default:

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

If you want to revert to the previous behaviour, just add the following in config/application.rb

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.