Reputation: 11
I want to allow users to embed content from my app into their sites. For this I have tried to get the following solution to run: Allow users to embed my content into their sites (like blogs) -- rails 4
Unfortunately, I am running into an issue with the iframe.src in embed.js, as it tries to access an "embed" folder on the user's file location:
GET file:///.../embed/1 net::ERR_FILE_NOT_FOUND
#public/embed.js
window.onload = function() {
//Params
var scriptPram = document.getElementById('load_widget');
var id = scriptPram.getAttribute('data-page');
/iFrame
var iframe = document.createElement('iframe');
iframe.style.display = "none";
iframe.src = "embed/" + id;
document.body.appendChild(iframe);
};
If I change the iframe.src to an absolute URL pointing to my app e.g. "http://localhost:3000/embed", then I run into a different error:
Refused to display 'http://localhost:3000/embed/1' in a frame because it set
'X-Frame-Options' to 'SAMEORIGIN'.
Sorry if this question might seem random, I'm on my first steps with ruby-on-rails. I promise to improve :)
Upvotes: 1
Views: 563
Reputation: 638
You need to modify your controller code and i hope it will work -
class Embed::PagesController < ApplicationController
layout false
after_action :allow_iframe, only: :show
def show
@page = Page.find params[:id]
end
private
def allow_iframe
response.headers.except! 'X-Frame-Options'
end
end
Upvotes: 1