F
F
Fean0r2020-09-10 10:42:37
Ruby on Rails
Fean0r, 2020-09-10 10:42:37

How to display a Rails application page inside an iframe?

I need to display my page which is part of an application on another page of that application inside an iframe

For example. I have page /customersand page /invoices(both actions are #index). On the page /invoicesthere is How iframeto src = 'http://localhost:3000/customers'

make it work correctly (and in the production environment too, i.e. example.com/invoicesshould display example.com/customerinside iframe)?

I already tried various solutions from StackOverflow:

  • Response.headers.delete ('X-Frame-Options')inside CustomerController#index(and before_action, and after_action, and right inside the action)
  • Install
    config.action_dispatch.default_headers = {'X-Frame-Options' => 'ALLOWALL'}

  • Remove headings per level ApplicationControlleras inCustomerController
  • Installresponse.headers ['X-Frame-Options'] = 'ALLOWALL'


But nothing works. Every time I get localhost refused to connectin Chrome and Firefox Can’t Open This Pagein Firefox.

Also doesn't work with relative path likeiframe src = '/customers'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fean0r, 2020-09-10
@Fean0r

As a result, the problem was that in the header of the http request, the rails added frame-ancestors: 'none'
Climbed into the config and changed

SecureHeaders::Configuration.default do |config|
  config.csp = {
    ...
    frame_ancestors:         %w['self'], # Replaced from frame_ancestors: %w['none'],
    ...
  }
end

Now everything is working properly, incl. and on localhost

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question