Rails 3 使用 raw() 渲染 iframe
所以我将 YouTube 上的整个嵌入代码存储到我的数据库中,然后像这样输出。
<%= raw(people.video) %>
它输出从 youtube 复制的通用 iframe 标记:
<iframe src="foo" width=400 height=380></iframe>
问题是它实际上显示该标记,而不是将视频嵌入到页面本身中。我可以通过将 src 存储在数据库中来解决这个问题......但这是迷你 cms 系统的一部分,站点管理员会发现从 YouTube 复制并粘贴嵌入代码会更容易。有什么办法我可以指定 iframe 实际渲染而不是仅仅在页面上吐出 html 吗?
So I am storing the whole embed code from youtube into my database and then outputting it like this.
<%= raw(people.video) %>
which outputs the general iframe tag copied from youtube:
<iframe src="foo" width=400 height=380></iframe>
the problem is that it actually displays that tag instead of embedding the video into the page itself. I can get around this just by storing the src in the database.... but this is part of a mini cms system and the site admins would find it much easier just to copy and past the embed code from youtube. Is there someway I can specify for the iframe to actually render instead of just spitting out the html on the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
raw
方法来呈现字符串的 HTML,您是否以这种方式存储它?您还可以尝试RedCloth
gem - 我能够像这样工作:这允许我的自定义 CMS 使用 Textile 标记
http://en.wikipedia.org/wiki/Textile_%28markup_language%29
我并不 100% 同意您所看到的内容,因为 raw 应该呈现 HTML,但您也可以尝试使用 JavaScript.write 包含嵌入标记,因为存在与嵌入到中的 Flash 对象相关的一些问题HTML 与 JavaScript。
如果这不起作用,请告诉我,如果可以,您可以提供屏幕截图或复制您在页面上看到的内容吗?
You can use the
raw
method to render the HTML of a string, are you storing it that way? You can also try theRedCloth
gem - I was able to get this working like so:Which allowed for my custom CMS to use the Textile markup
http://en.wikipedia.org/wiki/Textile_%28markup_language%29
I'm not 100% on what you're seeing, since raw should render HTML, but you might also try to include the embed tag using a JavaScript.write, since there are some issues related to Flash objects embedded in HTML vs JavaScript.
Let me know if this doesn't work, and if so, can you provide screenshots or copy what you're seeing on the page?