Rails 3.1 资源在服务器重新启动之前无法识别 rmagick 上传的新图像
我的 Rails 3.1.0
应用程序在 生产
环境中与 passenger
一起运行,并且我有一个部分,应用程序允许用户更改其个人资料图片,因此我使用 ajax 上传器上传图像,并在我的控制器中上传文件并使用 rmagick 为图像生成不同尺寸,然后使用 image_tag
渲染新图像,但应用程序不会显示图像直到我重新启动服务器。
我得到的是没有路由匹配[GET]“assets/path/to/image.png”
如果我重新启动服务器它将显示图像,但显然我不能每次都重新启动服务器一旦用户上传新图像。
如何解决保持资产正常运转的问题?
I have my Rails 3.1.0
application running with passenger
in production
environment and I have a section where the application allows the user to change his profile picture so I upload the image using an ajax uploader and in my controller I upload the file and generate different sizes for the image with rmagick then I render the new image with an image_tag
but the application won't show the image till I restart the server.
What I get is No route matches [GET] "assets/path/to/image.png"
If I restart the server It will show the image, but obviously I can't be restarting the server every once a user uploads a new image.
How can I solve the keeping the assets working the right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Rails 资产管道实际上适用于结构/设计图像,例如背景、图标、横幅等。)动态资产应该放在公共目录中[来源如下]
通过 Nginx 或 Apache 或任何您的 Web 服务器提供静态资产可能是一个好主意,或者将它们放在 Rails 应用程序的公共目录中。
这应该可以解决您的问题。例如,为静态资产创建一个单独的路径,您可以使用 rmagick / Carrierwave 或您喜欢的任何 gem 将这些图像上传到其中。
资产管道仅了解启动期间存在的图像。因此,将静态/上传的资源分离到一个单独的目录中,并直接通过网络服务器提供服务,将会有所帮助——它也应该更快。
您的配置中需要类似的内容:
更一般:
http:// railscasts.com/episodes/279-understanding-the-asset-pipeline
http://guides.rubyonrails.org/asset_pipeline.html
Rails 3.1:文件上传是否应该添加到资产管道中?
关于在资产管道之外提供图像:
http://mrjaba.posterous.com/rails-31-资产管道与 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
The Rails asset pipeline is really meant for structural / design images, such as backgrounds, icons, banners, etc..). Dynamic assets should go in the public directory [source below]
It's probably a good idea to serve static assets through Nginx or Apache or whatever your web-server is, or place them in the public directory of your Rails app.
That should solve your problem right there.. e.g. make a separate path for static assets into which you upload those images with rmagick / carrierwave, or whatever gem you prefer.
The asset pipeline only knows about images which are present during start-up. So separating static / uploaded assets into a separate directory , and serving it directly through the web-server, will help -- it should also be much faster.
you'll need something like this in your configuration:
More General:
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?
Regarding serving images outside 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