5

環境内でRails 3.1.0アプリケーションを実行しており、アプリケーションでユーザーがプロフィール写真を変更できるセクションがあるため、ajax アップローダーを使用して画像をアップロードし、コントローラーでファイルをアップロードし、rmagick で画像のさまざまなサイズを生成します次に、新しい画像をレンダリングしますが、サーバーを再起動するまでアプリケーションは画像を表示しません。passengerproductionimage_tag

私が得るものはNo route matches [GET] "assets/path/to/image.png"

サーバーを再起動すると画像が表示されますが、ユーザーが新しい画像をアップロードするたびにサーバーを再起動することはできません。

アセットを正しく機能させるにはどうすればよいですか?

4

1 に答える 1

6

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

于 2011-10-13T07:58:41.193 に答える