Mr_*_*zle 5 assets rmagick ruby-on-rails-3.1 ajaxuploader
我的Rails 3.1.0应用程序passenger在production环境中运行,我有一个部分,应用程序允许用户更改他的个人资料图片,所以我使用ajax上传器上传图像,在我的控制器中我上传文件并使用rmagick为图像生成不同的大小然后我使用a渲染新图像,image_tag但应用程序将不会显示图像,直到我重新启动服务器.
我得到的是 No route matches [GET] "assets/path/to/image.png"
如果我重新启动服务器它将显示图像,但显然我无法在用户上传新图像时重新启动服务器.
如何解决保持资产正常运行的问题?
Rails资产管道实际上是用于结构/设计图像,例如背景,图标,横幅等.).动态资产应该放在公共目录中[来源]
通过Nginx或Apache或任何您的Web服务器提供静态资产可能是一个好主意,或者将它们放在Rails应用程序的公共目录中.
这应该可以解决你的问题..例如,为你使用rmagick/carrierwave或你喜欢的任何宝石上传这些图像的静态资产创建一个单独的路径.
资产管道只知道启动期间存在的图像.因此,将静态/上载的资产分离到一个单独的目录中,并通过Web服务器直接提供它将有所帮助 - 它也应该更快.
在配置中你需要这样的东西:
# 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
Run Code Online (Sandbox Code Playgroud)
更多一般:
http://railscasts.com/episodes/279-understanding-the-asset-pipeline
http://guides.rubyonrails.org/asset_pipeline.html
关于在资产管道外提供图像:
http://mrjaba.posterous.com/rails-31-asset-pipeline-with-nginx-and-passen
http://trackingrails.com/posts/rails-31-and-asset-pipeline-problems-with-apache
https://github.com/defunkt/resque/issues/418
| 归档时间: |
|
| 查看次数: |
1990 次 |
| 最近记录: |