What is the best place to store static assets (files) in rails 3.1 ( pdf forms, xls files, etc)

佐手、 提交于 2020-01-02 01:14:10

问题


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?

thanks


回答1:


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"



回答2:


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.



来源:https://stackoverflow.com/questions/8581300/what-is-the-best-place-to-store-static-assets-files-in-rails-3-1-pdf-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!