Rails部分iframe缺少资产 [英] Rails partial iframe missing assets

查看:73
本文介绍了Rails部分iframe缺少资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个放置在其他网站(而不是我的网站)上的iframe,并呈现我网站的一部分.一切正常,但iframe(我的网站)的内容似乎没有包含任何资产.我正在使用Rails 4.0.4.我认为发生这种情况是因为application.html.erb未被加载,因为我只是渲染了部分图像.

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.

这是iframe代码:

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

推荐答案

您的控制器将如下所示:

Your controller would then look something like:

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

然后创建一个新的精简版式,名为"_iframe.html.erb"(或.haml或您使用的任何格式),仅包含资产和收益"(如果复制应用程序版式并删除部件,则很容易您不需要).

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).

请继续阅读: http://guides.rubyonrails.org/layouts_and_rendering.html 如果需要

这篇关于Rails部分iframe缺少资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆