iframe - How to override X-Frame-Options for a controller or action in Rails 4 -


rails 4 appears set default value of sameorigin x-frame-options http response header. great security, not allow parts of app available in iframe on different domain.

you can override value of x-frame-options globally using config.action_dispatch.default_headers setting:

config.action_dispatch.default_headers['x-frame-options'] = "allow-from https://apps.facebook.com" 

but how override single controller or action?

if want remove header completely, can create after_action filter:

class filescontroller < applicationcontroller   after_action :allow_iframe, only: :embed    def embed   end  private    def allow_iframe     response.headers.except! 'x-frame-options'   end end 

or, of course, can code after_action set value different:

class facebookcontroller < applicationcontroller   after_action :allow_facebook_iframe  private    def allow_facebook_iframe     response.headers['x-frame-options'] = 'allow-from https://apps.facebook.com'   end end 

note need clear cache in browsers (chrome me) while debugging this.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -