Rails 3.1 资源在服务器重新启动之前无法识别 rmagick 上传的新图像

发布于 2024-12-09 14:22:29 字数 367 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-12-16 14:22:29

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://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:

# 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文