ruby-on-rails-3.1 – Rails 3.1资产无法识别rmagick上传的新映
我的Rails 3.1.0应用程序在生产环境中与乘客一起运行,我有一个部分,应用程序允许用户更改他的个人资料图片,所以我使用ajax上传器上传图像,在我的控制器中我上传文件并生成不同的使用rmagick进行图像的大小然后我使用image_tag渲染新图像,但应用程序在重新启动服务器之前不会显示图像.
我得到的是没有路线匹配[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 更多一般: http://railscasts.com/episodes/279-understanding-the-asset-pipeline http://guides.rubyonrails.org/asset_pipeline.html Rails 3.1: Should File Uploads be added to asset pipeline? 关于在资产管道外提供图像: 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://pastebin.com/kC4Ba40U https://github.com/defunkt/resque/issues/418 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |