问题
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
回答1:
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
来源:https://stackoverflow.com/questions/22810287/rails-partial-iframe-missing-assets