Rails 中存储静态资源(文件)的最佳位置是什么(pdf 表单、xls 文件等)

发布于 2024-12-22 01:41:38 字数 127 浏览 3 评论 0原文

我有一堆静态资源(不是 jpg、css 和 js),而是我需要向用户提供的 pdf 表单、xls 等文件。他们很少改变。之前我习惯将它们存储在公共文件夹中,但是随着 Rails 3.1 中资产管道的引入,现在存储这样的文件的最佳位置是什么?

I have a bunch of static assets ( not jpg, css, & js) - rather files like pdf forms, xls that I need to serve to users. They rarely change. Before I used to store them in public folder, but with the introduction of the assets pipeline in rails 3.1 what is the best place to store files like that now now?

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

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

发布评论

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

评论(2

紫竹語嫣☆ 2024-12-29 01:41:38

实际上,我只是通过在 app/assets/files 中创建一个文件夹并将我的 xls 文件粘贴到其中来测试它,然后 rake asset:precompile 任务就拿起了它。

此外,还需要为 Rails 添加此 < 3.1:

    # Enable the asset pipeline
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/files"

Actually I just tested it by creating a folder in app/assets/files and sticking my xls files in there, and rake assets:precompile task just picked it up.

Also this needs to be added for Rails < 3.1:

    # Enable the asset pipeline
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/files"
夜清冷一曲。 2024-12-29 01:41:38

此类项目的最佳位置仍然是 /public 目录,请记住让您的 Web 服务器也直接提供这些资源。

仅当您想利用资产管道时才需要资产目录。资产管道处理从压缩和编译 .coffee.lesssass 文件到将 js 和 css 压缩到一个文件中的事情,以便您的网络服务器只需为每个服务提供一个文件。

当您使用 rake 任务 bundle exec rake assets:precompile 编译资产时,它们无论如何都会移至您的公共目录。

The best place for items like this is still in the /public directory, remember to have your web server serve these assets directly also.

The assets directory is only needed if you want to take advantage of the asset pipeline. The asset pipeline handles things from compressing and compiling .coffee and .less or sass files to compressing your js and css into one file so your webserver only has to serve one file for each.

When you compile your assets with the rake task bundle exec rake assets:precompile they are moved to your public directory anyhow.

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