Rails 资产管道实际上适用于结构/设计图像,例如背景、图标、横幅等。)动态资产应该放在公共目录中[来源如下]
通过 Nginx 或 Apache 或任何 Web 服务器提供静态资源可能是个好主意,或者将它们放在 Rails 应用程序的公共目录中。
那应该可以解决你的问题......例如为静态资源创建一个单独的路径,您可以使用 rmagick / Carrierwave 或任何您喜欢的 gem 将这些图像上传到其中。
资产管道仅了解启动期间存在的图像。因此,将静态/上传的资源分离到一个单独的目录中,并直接通过网络服务器提供服务,将会有所帮助——它也应该更快。
你的配置中需要这样的东西:
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# UNCOMMENT the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
更一般:
http://railscasts.com/episodes/279-understanding-the-asset-pipeline http://railscasts.com/episodes/279-understanding-the-asset-pipeline
http://guides.rubyonrails.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.html
Rails 3.1:文件上传是否应该添加到资产管道中? https://stackoverflow.com/questions/7391938/rails-3-1-should-file-uploads-be-added-to-asset-pipeline
关于在资产管道之外提供图像:
http://mrjaba.posterous.com/rails-31-asset-pipeline-with-nginx-and-passen http://mrjaba.posterous.com/rails-31-asset-pipeline-with-nginx-and-passen
http://trackingrails.com/posts/rails-31-and-asset-pipeline-problems-with-apache http://trackingrails.com/posts/rails-31-and-asset-pipeline-problems-with-apache
http://pastebin.com/kC4Ba40U http://pastebin.com/kC4Ba40U
https://github.com/defunkt/resque/issues/418 https://github.com/defunkt/resque/issues/418