user4713761
user4713761

Reputation:

How do run a local HTML file in an iframe within my rails 4 app

Rails 4.2, Ruby 2.1.2

I have an html file that right now just lives in the public folder of my app. I am trying to figure out how to serve the content of that file within an iframe from the app. The html file is an articulate storyline (but I don't think that really matters). I am sure that the file needs to "speak" with the browser to make some determinations on how to render content i.e. flash, HTML5 etc... the file looks like this:

<!DOCTYPE HTML>
<html style="height: 100%;">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<!-- Created using Articulate Storyline 1.2 - http://www.articulate.com  --> 
<!-- version: 1.2.1212.1412 --> 
<!-- saved from url=(0014)about:internet -->

<title>BasicSearch1</title>
<style>
body { margin: 0px; } 
object {outline: none;}
</style>
<script>
var g_bHtml5Supported = true;
</script>
<!--[if lte IE 9]><script>g_bHtml5Supported = false;</script><![endif]-->

<script type="text/javascript">

// Detect min flash version
var g_bMinFlash = false;

if (navigator.plugins["Shockwave Flash"])
{
var arrDescription = navigator.plugins["Shockwave Flash"].description.split(" ");
var nVersion = Number(arrDescription[arrDescription.length - 2]);

g_bMinFlash = (nVersion >= 10) || isNaN(nVersion);
}

... etc

Understanding that this is JavaScript . . .

I have tried the following things with some limited success:

Idea 1)

Within my controller . . .

@file = File.join(Rails.root, "public/asl_files/BasicSearch1/story.html")

Within the view . . .

<iframe src="<% @file %>"></iframe>

result: this one renders the iframe fine, but its just blank white inside.

idea 2)

Within my controller . . .

@file = show_asl

  def show_asl
   asl_filename = File.join(Rails.root, "public/asl_files/BasicSearch1/story.html")
   send_file(asl_filename, :filename => "story.html", :type => "text/html; charset=utf-8", disposition: "inline")
  end

Within the view . . .

<iframe src="<% @file %>"></iframe>

result: this one doesn't look like it renders a defined iframe, instead turns the whole page grey.

Upvotes: 1

Views: 2836

Answers (1)

Jason Huang
Jason Huang

Reputation: 131

Rails prevent iframe by default Try add this into your config

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

Upvotes: 1

Related Questions