Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Rails 4.1.6资产管道未在生产中加载资产和javascript_Ruby_Ruby On Rails 4_Asset Pipeline_Erb_Production - Fatal编程技术网

Ruby Rails 4.1.6资产管道未在生产中加载资产和javascript

Ruby Rails 4.1.6资产管道未在生产中加载资产和javascript,ruby,ruby-on-rails-4,asset-pipeline,erb,production,Ruby,Ruby On Rails 4,Asset Pipeline,Erb,Production,我有一个RubyonRails web服务器,我正试图在生产中部署它。我在将资产加载到生产中时遇到了问题:.css、.js和图像(在开发过程中似乎工作正常,原因是) 这是我的产品 Rails.application.configure do # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of

我有一个RubyonRails web服务器,我正试图在生产中部署它。我在将资产加载到生产中时遇到了问题:.css、.js和图像(在开发过程中似乎工作正常,原因是)

这是我的产品

Rails.application.configure do

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  config.serve_static_files = true

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Generate digests for assets URLs.
  config.assets.digest = true
end
我曾经拥有同一台服务器的部署版本,其标记在application.html.erb中如下所示:

<head>
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>

正确%>
正确%>
生产中(加载css/js)


现在部署我的应用程序时,它看起来是这样的(没有指纹)。预编译似乎不起作用。公共/资产中没有生成文件,这是一个问题。当前我的应用程序清单如下所示

<link data-turbolinks-track="true" href="/stylesheets/application.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/javascripts/application.js"></script>

我认为在资产管道和预编译资产方面存在一些问题。它应该生成css和js的指纹版本并使用它们。即使在我的生产服务器上运行rake资产:预编译也不起作用。如何让rails使用指纹版本

在使用某些设置时,我可以通过更改这些设置使其工作:

config.assets.compile = true


Rails.application.config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
config.assets.compile=true

Rails.application.config.assets.precompile,因此它是一个简单的解决方案。我使用docker推进生产,需要将这一行添加到docker文件中

RUN rake assets:precompile
这将预编译资产并添加指纹,以便在生产中提供服务。干杯

RUN rake assets:precompile