Rails partial iframe missing assets

风流意气都作罢 提交于 2019-12-08 09:48:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!