在 Rails 中渲染动态横幅的公共 html?

发布于 2024-08-30 04:12:18 字数 351 浏览 2 评论 0原文

我想渲染特定的 HTML 片段来显示横幅,因为每个横幅都有不同的性质(一些图像,一些 Flash 等)。每个横幅文件都位于 app/public/banners/ 下。我尝试了很多方法,例如:

render :file => "/banners/somebanner.html"

但它无法找到该文件,因为 Rails 在 app/views 下查找。有什么想法吗?谢谢!

视图路径app/views中缺少模板banners/somebanner.html

I would like to render specific HTML snippets for displaying banners, because each banner has a different nature (some images, some flash, etc). Every banner file is under app/public/banners/. I tried many ways, like:

render :file => "/banners/somebanner.html"

But it can't locate the file, because Rails looks under app/views. Any ideas ? Thanks!

Missing template banners/somebanner.html in view path app/views

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以可爱出名 2024-09-06 04:12:18

我从来没有厌倦过,但刚刚发现 Google 上的这篇文章

render :file => "#{RAILS_ROOT}/public/banners/somebanner.html"

看起来可能会有一些缓存副作用,即使在开发模式下

http://workingwithrails.com/forums/4-ask-a-rails-expert/ topic/1178-render-file-rails-root-public-layouts-mylayout-cached

你可能也想要:layout =>错误的

I've never tired it but just found this post on Google

render :file => "#{RAILS_ROOT}/public/banners/somebanner.html"

looks like there might be some caching side-effects, even in development mode

http://workingwithrails.com/forums/4-ask-a-rails-expert/topics/1178-render-file-rails-root-public-layouts-mylayout-cached

also you probably want :layout => false with that

酒废 2024-09-06 04:12:18

临时修复:

将“public/banners”移至“app/views/banners”,然后在“/public”中创建符号链接,以便我的团队可以添加新横幅

Temporary Fix:

Moved 'public/banners' to 'app/views/banners' and then made a synmlink in '/public' so my team can add new banners

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文