質問

いレールアプリようにしているテストの生産環境です。を行った RAILS_ENV=production rake assets:precompile 発生するすべての資産を公共資産とします。問題は、また私のアプリw/ RAILS_ENV=production rails s thin 取得します:

ActionController::RoutingError (No route matches [GET] "/assets/application-eff78fd67423795a7be3aa21512f0bd2.css"):

このファイルに存在するもので /public/assets/application-eff78fd67423795a7be3aa21512f0bd2.css.

意思い理由としては、もしかしたらこ RoutingError?

役に立ちましたか?

解決

本番モードでは、Railsは、静的な資産を提供するための責任を負いません。そのため、あなたはこのエラーを得ています。それはRailsの単なるラッパーなので薄いが、どちらかそれを行うことはありません。

これは、アプリケーションでconfig/environments/production.rbでこの設定によって制御されます:

config.serve_static_files = false

またはレールで5:

# config/environments/production.rb
config.public_file_server.enabled = true

またはtrueに設定ENV['RAILS_SERVE_STATIC_FILES']ます。

あなたはどちらかそれtrueに設定するか、静的な資産を提供しますどのApacheやnginxのように実サーバを使用することができます。私はパウもそれを行うことが疑わます。

<時間> あなたはHerokuのにしている場合は、

、彼らはデフォルトでこの設定を有効にrails_12factor宝石を使用することをお勧めします。

:このように、あなたのproductionGemfileグループに宝石を置きます
group :production do
  gem 'rails_12factor'
end

他のヒント

ライアンは上記の言ったことに加え、Railsのアセットパイプラインガイドはあなたのための静的な資産を提供するためにどのようにセットアップApacheやnginxのに説明します。

http://guides.rubyonrails.org/asset_pipeline.html

彼らははるかに優れた雑種/薄い/ユニコーンよりも、このタスク用に最適化しているとして、

あなたは本当にセットアップnginxのか、Apacheは、静的な資産を提供する必要があります。

で解決し、同じ問題です。私の場合ライアンの答えませんでした。Bratscheを指摘のレールガイド、残念ながらこの動作しなかった私にとってます。しかし、資源の役に立てた。いたに割の設定が追加される rohs指摘し、公開ディレクトリです。こうまくいきませんでした。

   # serve static assets
   location ~ ^/assets/ {
     expires 1y;
     root  /path/to/my/cool_project/public;
     add_header Cache-Control public;

     add_header ETag "";
     break;
   }

再起動nginxことになるのです。

確かに、あなたは、任意のデフォルトのconfigsを変更する必要はありませんでした。 あなただけの再びの再コンパイル資産ファイルの。

パブリック/資産を削除する

1.rake資産:クロバーRAILS_ENV =生産

資産コンパイル

2.rake資産:プリコンパイルRAILS_ENV =生産

3.restartサーバ、例えば(nginxの)

Rails 4.2 has added/changed this line in your config/environments/ staging.rb and production.rb files:

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

If RAILS_SERVE_STATIC_FILES is not set, and you are service assets from your Rails server (like with Unicorn), then it will default to "false", and the RoutingError will occur.

This is an easy fix:

config.serve_static_files = true

In rails 5, the config.serve_static_files option has changed, so now you need to have

config.public_file_server.enabled = true

to serve assets locally.

try below code:

config/environments/production.rb

config.assets.compile = true

then run command:

RAILS_ENV=production rake assets:precompile

then push all compiles files and manifest file to server.

I use mina+puma+nginx to deploy my Rails 5 application, I got

ActionController::RoutingError (No route matches [GET] "/assets/application-658cf2ab3ac93aa5cb41a762b52cf49d7184509c307922cd3fbb61b237a59c1a.css")

check config/environments/production.rb

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

NGINX already handles this, config it corretcly

upstream puma {
  server unix:///home/deploy/apps/appname/shared/tmp/sockets/appname-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /home/deploy/apps/appname/current/public;
  access_log /home/deploy/apps/appname/current/log/nginx.access.log;
  error_log /home/deploy/apps/appname/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

things will work fine.

If somebody get here with the same error in the test environment as I do, here's what helped me:

rails assets:clobber assets:precompile RAILS_ENV=test

then:

ps axu | grep your-username

to find spring server process and his PID then kill it via:

kill <spring-server-PID>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top