Rails 3.1.1中的静态页面和资产 [英] Static pages and assets in Rails 3.1.1

查看:46
本文介绍了Rails 3.1.1中的静态页面和资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在从事一个项目,在该项目中,我们需要不时地放入静态"的那些静态html页面+静态资产.我们不能让任何人直接编辑html来放置资产的路径.我们需要它来简单地工作,以便将html +资产文件夹直接放置到/public中,并在生成内容时提供内容.

Currently working on a project where we need to drop in various static html pages + static assets for those from time to time that "just work." We cannot have anyone editing the html directly to place paths in for the assets. We need it to simply work such that the html + asset folders are placed directly into /public and the content is served up as it was generated.

在生产中测试此行为时,绝对不会出现错误,例如:

When testing this behavior in production, it's a no go with errors such as:

ActionController::RoutingError (No route matches [GET] "/some_folder/some-image.png"):

我认为这是我从3.1.x资产管道中读取的结果.

I assume this is a result from what I'm reading from 3.1.x's asset pipeline.

您如何更改路线以使这些路线可以直接送达?还是有保持这种精确行为的首选方法? (最终它将部署在heroku上.)

How do you alter the routes such that these will be served up directly? Or is there a preferred way to keep this precise behavior? (Ultimately this will be deployed on heroku.)

添加更多详细信息,因为当前的评论尚未将我的问题推到解决方案的边缘:

在当前情况下,我将直接在WEBrick rails s -e production上对其进行测试.在开发模式下,它确实可以正常工作;唯一的例外是在production中.

In my present scenario I'm running it straight on WEBrick rails s -e production to test it out. In development mode this does work properly; the only exception is in production.

在运行服务器之前,我也正在运行此命令: bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile --trace

I am also running this prior to running the server: bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile --trace

当我实际尝试在生产环境中加载页面时,我看到以下输出:

When I actually attempt to load the page in production, I see the following output:

cache: [GET /] miss
cache: [GET /test_files/index.css] miss
cache: [GET /test_files/index.js] miss
cache: [GET /test_files/logo.png] miss
cache: [GET /test_files/background.png] miss
cache: [GET /test_files/horizontal.png] miss
cache: [GET /favicon.ico] miss

推荐答案

在进一步检查production.rb时,我看到:"config.serve_static_assets = true"默认情况下设置为false会引起webrick遇到的问题.因此,将其设置为true时,可以正确存储文件.

Upon further scrutiny of the production.rb I am seeing: "config.serve_static_assets = true" that when set to false by default evokes the issue experienced in webrick. So when setting that to true it serves the files up properly.

从其他一些阅读资料来看,似乎Heroku也需要将此设置设置为false,这就是我们要部署到的环境.

From some additional reading it appears that perhaps Heroku needs this set to false as well, which is the environment to which we're deploying.

感谢您的投入,但是这似乎是目前采取的方法,如果这不是正确的答案或有更好的方法,我当然会感谢您的进一步投入.

Thanks for the input, but this appears to be the approach to take for now and I'd certainly appreciate any further input if this is NOT the correct answer or if there's a better approach.

这篇关于Rails 3.1.1中的静态页面和资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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