2017-04-05 7 views
1

ユーザーが自分のアプリケーションのコンテンツをサイトに埋め込むことを許可します。このため私は以下の解決策を実行しようとしました:Allow users to embed my content into their sites (like blogs) -- rails 4ユーザーが自分のコンテンツを自分のサイトに埋め込むことを許可する - レール4(フォローアップ)

残念ながら、私はembed.jsのiframe.srcに関する問題に遭遇しています。ユーザーのファイルの「埋め込み」フォルダにアクセスしようとしています場所:

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); 
}; 

私は私のアプリなどを指す絶対URLにiframe.srcを変更した場合「http://localhost:3000/embed」は、その後、私は別のエラーに遭遇:この質問はランダムに見えるかもしれませんがあれば

Refused to display 'http://localhost:3000/embed/1' in a frame because it set 
'X-Frame-Options' to 'SAMEORIGIN'. 

申し訳ありませんが、私はルビーオンレールと私の最初のステップでよ。私が改善することを約束:)

答えて

0

あなたのコントローラのコードを変更する必要があり、私はそれが仕事を願っています -

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 
+1

おかげでたくさん - それはそのように動作するようになりました! – bstone

関連する問題