Rails应用程序在生产环境中不提供资产。

时间:2022-11-10 20:37:52

My app works fine when run in development environment. In production (rails server -e production), the browser can't access the css and js files and on the console there are messages like:

我的应用程序在开发环境下运行时运行良好。在产品(rails server -e产品)中,浏览器不能访问css和js文件,控制台有如下消息:

I, [2013-07-27T21:00:59.105459 #11449]  INFO -- : Started GET "/javascripts/application.js" for 99.102.22.124 at 2013-07-27 21:00:59 +0000
F, [2013-07-27T21:00:59.108302 #11449] FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/javascripts/application.js"):

The head section from html source when in production environment:

在生产环境中来自html源代码的头部部分:

<head>
  <title>a Social Server</title>
  <link data-turbolinks-track="true" href="/stylesheets/application.css" media="all" rel="stylesheet">
  <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
  <script data-turbolinks-track="true" src="/javascripts/application.js"></script>
  <meta content="authenticity_token" name="csrf-param">
<meta content="jYM4IAXTXAuKWeD4FEVrXgXRNFeB6EazU68ZBQfRqNY=" name="csrf-token">
</head>

In development env on the other hand the head section looks like:

在开发环境另一方面,头部部分看起来是:

<head>
  <title>a Social Server</title>
  <link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/twitter-bootstrap-static/bootstrap.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/twitter-bootstrap-static/fontawesome.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/bootstrap_and_overrides.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/instagram.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/socialserver.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.core.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.theme.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.accordion.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.menu.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.autocomplete.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.button.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.datepicker.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.resizable.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.dialog.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.progressbar.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.selectable.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.slider.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.spinner.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.tabs.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.tooltip.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.base.css?body=1" media="all" rel="stylesheet">
<link data-turbolinks-track="true" href="/assets/jquery.ui.all.css?body=1" media="all" rel="stylesheet">
  <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
  <script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-transition.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-alert.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-modal.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-tab.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-popover.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-button.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-collapse.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-carousel.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap/bootstrap-affix.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/twitter/bootstrap.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/bootstrap.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.core.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.widget.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.accordion.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.position.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.menu.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.autocomplete.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.button.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.datepicker.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.mouse.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.draggable.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.resizable.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.dialog.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.droppable.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-blind.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-bounce.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-clip.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-drop.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-explode.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-fade.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-fold.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-highlight.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-pulsate.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-scale.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-shake.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-slide.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.effect-transfer.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.progressbar.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.selectable.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.slider.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.sortable.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.spinner.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.tabs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.tooltip.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery.ui.all.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
  <meta content="authenticity_token" name="csrf-param">
<meta content="jYM4IAXTXAuKWeD4FEVrXgXRNFeB6EazU68ZBQfRqNY=" name="csrf-token">
</head>

The app does not use a database, so I have disabled ActiveRecord. Snippets of the config files:

应用程序不使用数据库,所以我禁用了ActiveRecord。配置文件的片段:

application.rb

application.rb

require File.expand_path('../boot', __FILE__)
#require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
Bundler.require(:default, Rails.env)
module Socialserver
  class Application < Rails::Application
  end
end

production.rb

production.rb

Socialserver::Application.configure do
   config.cache_classes = true
   config.eager_load = true
   config.consider_all_requests_local       = false
   config.action_controller.perform_caching = true
   config.serve_static_assets = false
   config.assets.js_compressor = :uglifier
   config.assets.compile = false
   config.assets.digest = true
   config.assets.version = '1.0'
   config.log_level = :info
   config.i18n.fallbacks = true
   config.active_support.deprecation = :notify
   config.log_formatter = ::Logger::Formatter.new
   config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
   config.assets.precompile += %w( .svg .eot .woff .ttf )
end

development.rb:

development.rb:

Socialserver::Application.configure do
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  config.active_support.deprecation = :log
  config.assets.debug = true
end

Gemfile:

Gemfile:

source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
  gem 'sdoc', require: false
end
group :twitter do
  gem 'twitter', '4.8.1'
end
group :instagram do
  gem 'instagram', '0.10.0'
end
group :tumblr do
  gem 'tumblr_client'
end
gem 'twitter-bootstrap-rails'
gem 'therubyracer' #needed for runtime js on amazon ec2.

I apologize for posting so much info. I felt the info might be relevant.

我很抱歉发布了这么多信息。我觉得这个信息可能是相关的。

p.s. I have only half baked knowledge of rails, so bear with me. Thanks~

附注:我对rails的知识还不太了解,请见谅。谢谢~

7 个解决方案

#1


66  

When testing locally your production environment, you have to compile the assets locally. Simply run the command below:

在本地测试生产环境时,必须在本地编译资产。只需运行以下命令:

RAILS_ENV=production bundle exec rake assets:precompile

It will generate all the assets under public/assets.

它将生成公共/资产项下的所有资产。

Next, you have to tell Rails to serve the assets itself. Server software (eg. Nginx or Apache) do it for you on environments like Heroku, but locally you should let Rails do it. Change this in your production.rb:

接下来,您必须告诉Rails为资产本身服务。服务器软件(如。Nginx或Apache)在Heroku这样的环境中为您做,但是在本地应该让Rails来做。在你的产品中改变这一点。

config.serve_static_assets = true

But make sure you set it back to false before pushing your code to production!

但是在将代码推向产品之前,请确保将其设置为false !

#2


37  

This sounds like to the problem I was having.

这听起来像是我遇到的问题。

I found a blog that suggests this is a bug in the Rails 4.0.0 asset pipeline, and is inexplicably mitigated by setting...

我发现了一个博客,它表明这是Rails 4.0.0资产管道中的一个缺陷,并且通过设置令人费解地减轻了……

config.assets.compile = true

... in config/environments/production.rb

…在config /环境/ production.rb

Aside from somehow kicking the asset pipeline in to actually working, that setting will turn on live-compilation of assets. That is normally a bad thing for performance in production, but if you still manually precompile assets when you deploy, with

除了以某种方式将资产管道踢入实际工作之外,该设置将启动资产的实时编译。这通常对产品性能不好,但是如果您在部署时仍然手动预编译资产,则使用

rake assets:precompile

... the live-compilation should never happen (because the necessary assets have already been precompiled).

…实时编译不应该发生(因为必要的资产已经被预先编译)。

I hope this helps :)

我希望这能有所帮助。

#3


10  

As previously noted config.serve_static_assets is deprecated and replaced by config.serve_static_files. If one examines config/environments/production.rb for Rails-4.2 then one finds this:

如前所述配置。serve_static_assets被弃用,被config.serve_static_files替换。如果一个人检查配置/环境/生产。轨道rb -4.2则发现:

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

The implication being that setting and exporting (in BASH) the environment variable export RAILS_SERVE_STATIC_FILES="to any value whatsoever" in a session prior to running rails s -e production will give the desired result when testing locally and also will avoid having to remember to recode production.rb before pushing to the production host.

其含义是,在运行rails s -e产品之前,在会话中设置并导出(在BASH中)环境变量RAILS_SERVE_STATIC_FILES=“任何值”,将在本地测试时得到所需的结果,并且还将避免记住重新编码生产。在推进到生产主机之前。

#4


6  

In production.rb change the setting:

在生产中。rb:修改设置

rails 3.x

rails 3.倍

config.serve_static_assets = true

rails 4.x

rails 4.倍

config.serve_static_files = true

#5


3  

I think to Rails 4.x you have to precompile assets to production or use config.assets.compile even both if needed.

我认为是Rails 4。必须将资产预编译到生产环境中,或者使用config. asset.即使需要也要编译。

The default Rails behavior for production environment is to "Do not fallback to assets pipeline if a precompiled asset is missed." So, don't. Use to not compi

生产环境的默认Rails行为是“如果错过了预编译的资产,不要退回到资产管道”。所以,不要。使用不compi

config.assets.compile = false

If you use this option you don't need to use:

如果你使用这个选项,你不需要使用:

config.serve_static_files = true

Because if the asset wasn't precompiled, Rails will compile before serve request.

因为如果没有预先编译资产,Rails将在服务请求之前编译。

But if you do precompile the assets before production you don't needs config.assets.compile = true, but you need config.serve_static_files = true to Rails serve requests if you don't have http_server to serve the precompiled assets.

但是,如果在生产之前预编译资产,则不需要config. asset. compile = true,但需要配置。如果没有http_server来服务预编译的资产,serve_static_files =对Rails服务请求。

The setting config.serve_static_assets is deprecated.

设置配置。serve_static_assets弃用。

DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly.

I hope this answer help you(reader) to understand whats really happens

我希望这个答案能帮助你理解到底发生了什么。

#6


3  

Check for a file like this:

检查这样的文件:

public/assets/.sprockets-manifest-3f7771d777ceb581d754e4fad88aa69c.json

If you are pushing precompiled assets to a production server there is a chance that you are preventing hidden 'dot' files being pushed and this essential file won't make it into production.

如果您将预编译的资产推送到生产服务器,则有可能会阻止隐藏的“点”文件被推送,而这个基本文件不会将其投入生产。

In my environment I need to precompile assets in an integration environment and push these to production so that there is no need to compile the assets on the production machine. I was erroneously blocking all hidden files from being pushed to production machine.

在我的环境中,我需要在集成环境中预编译资产,并将它们推到生产环境中,这样就不需要在生产机器上编译资产。我错误地阻止了所有隐藏文件被推到生产机器上。

To see if this answer works for you, check your generated HTML source in a browser from the production server to see if the assets path has been generated. If you see your script tag like this:

要查看这个答案是否对您有用,请在生产服务器的浏览器中检查生成的HTML源代码,看看是否生成了资产路径。如果你看到你的脚本标签像这样:

<script data-turbolinks-track="true" src="/javascripts/application.js"></script>

check the src attribute. It should start with /assets/javascript. In this case it starts with /javascript which indicates Rails does not think any of the assets have been precompiled.

检查src属性。它应该从/assets/javascript开始。在这种情况下,它从/javascript开始,这表明Rails不认为任何资产已经预先编译。

I corrected this by updating my push to production (currently rsync), ensuring I push the .sprockets-manifest* file after precompiling on my integration server.

我通过更新我的产品推送(当前的rsync)来纠正这一点,确保在集成服务器上预编译后按下.sprockets-manifest*文件。

Also, I use standalone Passenger as my integration test server, rather than Webrick, since it handles more realistic serving of static files.

此外,我使用独立的过客作为集成测试服务器,而不是Webrick,因为它处理更实际的静态文件服务。

#7


0  

The following command works for me locally.

以下命令在本地对我有效。

rails server -e production

I got the same error "ActionController::RoutingError (No route matches [GET] "/assets/application.css"" while running "rails s". Even after I precompiled the source, change config precompile true. It still could not load properly.

我得到了相同的错误“ActionController: RoutingError(没有路径匹配[GET]”/assets/application。运行“rails s”时使用css。即使在预编译源代码之后,更改配置预编译为true。它仍然不能正常装载。

The option "-e production" made those RoutingError disappear.

选项“-e生产”使这些例行错误消失。

#1


66  

When testing locally your production environment, you have to compile the assets locally. Simply run the command below:

在本地测试生产环境时,必须在本地编译资产。只需运行以下命令:

RAILS_ENV=production bundle exec rake assets:precompile

It will generate all the assets under public/assets.

它将生成公共/资产项下的所有资产。

Next, you have to tell Rails to serve the assets itself. Server software (eg. Nginx or Apache) do it for you on environments like Heroku, but locally you should let Rails do it. Change this in your production.rb:

接下来,您必须告诉Rails为资产本身服务。服务器软件(如。Nginx或Apache)在Heroku这样的环境中为您做,但是在本地应该让Rails来做。在你的产品中改变这一点。

config.serve_static_assets = true

But make sure you set it back to false before pushing your code to production!

但是在将代码推向产品之前,请确保将其设置为false !

#2


37  

This sounds like to the problem I was having.

这听起来像是我遇到的问题。

I found a blog that suggests this is a bug in the Rails 4.0.0 asset pipeline, and is inexplicably mitigated by setting...

我发现了一个博客,它表明这是Rails 4.0.0资产管道中的一个缺陷,并且通过设置令人费解地减轻了……

config.assets.compile = true

... in config/environments/production.rb

…在config /环境/ production.rb

Aside from somehow kicking the asset pipeline in to actually working, that setting will turn on live-compilation of assets. That is normally a bad thing for performance in production, but if you still manually precompile assets when you deploy, with

除了以某种方式将资产管道踢入实际工作之外,该设置将启动资产的实时编译。这通常对产品性能不好,但是如果您在部署时仍然手动预编译资产,则使用

rake assets:precompile

... the live-compilation should never happen (because the necessary assets have already been precompiled).

…实时编译不应该发生(因为必要的资产已经被预先编译)。

I hope this helps :)

我希望这能有所帮助。

#3


10  

As previously noted config.serve_static_assets is deprecated and replaced by config.serve_static_files. If one examines config/environments/production.rb for Rails-4.2 then one finds this:

如前所述配置。serve_static_assets被弃用,被config.serve_static_files替换。如果一个人检查配置/环境/生产。轨道rb -4.2则发现:

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

The implication being that setting and exporting (in BASH) the environment variable export RAILS_SERVE_STATIC_FILES="to any value whatsoever" in a session prior to running rails s -e production will give the desired result when testing locally and also will avoid having to remember to recode production.rb before pushing to the production host.

其含义是,在运行rails s -e产品之前,在会话中设置并导出(在BASH中)环境变量RAILS_SERVE_STATIC_FILES=“任何值”,将在本地测试时得到所需的结果,并且还将避免记住重新编码生产。在推进到生产主机之前。

#4


6  

In production.rb change the setting:

在生产中。rb:修改设置

rails 3.x

rails 3.倍

config.serve_static_assets = true

rails 4.x

rails 4.倍

config.serve_static_files = true

#5


3  

I think to Rails 4.x you have to precompile assets to production or use config.assets.compile even both if needed.

我认为是Rails 4。必须将资产预编译到生产环境中,或者使用config. asset.即使需要也要编译。

The default Rails behavior for production environment is to "Do not fallback to assets pipeline if a precompiled asset is missed." So, don't. Use to not compi

生产环境的默认Rails行为是“如果错过了预编译的资产,不要退回到资产管道”。所以,不要。使用不compi

config.assets.compile = false

If you use this option you don't need to use:

如果你使用这个选项,你不需要使用:

config.serve_static_files = true

Because if the asset wasn't precompiled, Rails will compile before serve request.

因为如果没有预先编译资产,Rails将在服务请求之前编译。

But if you do precompile the assets before production you don't needs config.assets.compile = true, but you need config.serve_static_files = true to Rails serve requests if you don't have http_server to serve the precompiled assets.

但是,如果在生产之前预编译资产,则不需要config. asset. compile = true,但需要配置。如果没有http_server来服务预编译的资产,serve_static_files =对Rails服务请求。

The setting config.serve_static_assets is deprecated.

设置配置。serve_static_assets弃用。

DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly.

I hope this answer help you(reader) to understand whats really happens

我希望这个答案能帮助你理解到底发生了什么。

#6


3  

Check for a file like this:

检查这样的文件:

public/assets/.sprockets-manifest-3f7771d777ceb581d754e4fad88aa69c.json

If you are pushing precompiled assets to a production server there is a chance that you are preventing hidden 'dot' files being pushed and this essential file won't make it into production.

如果您将预编译的资产推送到生产服务器,则有可能会阻止隐藏的“点”文件被推送,而这个基本文件不会将其投入生产。

In my environment I need to precompile assets in an integration environment and push these to production so that there is no need to compile the assets on the production machine. I was erroneously blocking all hidden files from being pushed to production machine.

在我的环境中,我需要在集成环境中预编译资产,并将它们推到生产环境中,这样就不需要在生产机器上编译资产。我错误地阻止了所有隐藏文件被推到生产机器上。

To see if this answer works for you, check your generated HTML source in a browser from the production server to see if the assets path has been generated. If you see your script tag like this:

要查看这个答案是否对您有用,请在生产服务器的浏览器中检查生成的HTML源代码,看看是否生成了资产路径。如果你看到你的脚本标签像这样:

<script data-turbolinks-track="true" src="/javascripts/application.js"></script>

check the src attribute. It should start with /assets/javascript. In this case it starts with /javascript which indicates Rails does not think any of the assets have been precompiled.

检查src属性。它应该从/assets/javascript开始。在这种情况下,它从/javascript开始,这表明Rails不认为任何资产已经预先编译。

I corrected this by updating my push to production (currently rsync), ensuring I push the .sprockets-manifest* file after precompiling on my integration server.

我通过更新我的产品推送(当前的rsync)来纠正这一点,确保在集成服务器上预编译后按下.sprockets-manifest*文件。

Also, I use standalone Passenger as my integration test server, rather than Webrick, since it handles more realistic serving of static files.

此外,我使用独立的过客作为集成测试服务器,而不是Webrick,因为它处理更实际的静态文件服务。

#7


0  

The following command works for me locally.

以下命令在本地对我有效。

rails server -e production

I got the same error "ActionController::RoutingError (No route matches [GET] "/assets/application.css"" while running "rails s". Even after I precompiled the source, change config precompile true. It still could not load properly.

我得到了相同的错误“ActionController: RoutingError(没有路径匹配[GET]”/assets/application。运行“rails s”时使用css。即使在预编译源代码之后,更改配置预编译为true。它仍然不能正常装载。

The option "-e production" made those RoutingError disappear.

选项“-e生产”使这些例行错误消失。