Question

I'm trying to create an iframe that's placed on an other website (not mine) and renders one partial of my site. Everything works well but the content of the iframe (my site) doesn't seem to have any assets included. I'm using Rails 4.0.4. I think it happens because the application.html.erb isn't loaded because I'm just rendering a partial.

Here is the iframe code:

<iframe src="<%= url_for controller: 'welcome', action: 'iframe' %>" scrollbars="auto" height="480" width="320" name="RiverOfNews"></iframe>

And here is the corresponding controller method:

def iframe
  load_channels
  render :partial => 'news'
end
Was it helpful?

Solution

Your controller would then look something like:

class WelcomeController < ApplicationController
  def iframe
    load_channels
    render :partial => "news", :layout => "iframe"
  end
end

And then you create a new stripped down layout named "_iframe.html.erb" (or .haml or whatever you use) containing only your assets and the "yield" (easy if you copy your application layout and remove the parts you don't need).

Read up on: http://guides.rubyonrails.org/layouts_and_rendering.html if needed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top