javascript_include_tag Rails 4生成"/javascripts/"而不是"/资产"在生产中 [英] javascript_include_tag Rails 4 generating "/javascripts/" instead of "/assets" in production

查看:59
本文介绍了javascript_include_tag Rails 4生成"/javascripts/"而不是"/资产"在生产中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有

<%= javascript_include_tag "modernizr", "data-turbolinks-track" => true %>

在头上.在开发中,呈现了以下HTML,并加载了modernizr:

in the head. In development, the following HTML is rendered, and modernizr is loaded:

<script data-turbolinks-track="true" src="/assets/modernizr.js?body=1"></script>

在生产中,呈现了后续的HTML,并且未加载modernizr(未找到404):

In production, the followign HTML is rendered, and modernizr is not loaded (404 not found):

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

在生产中,找到了/assets/modernizr.js并且可以浏览.

In production, /assets/modernizr.js is found and browsable.

Rails文档说, javascript_include_tag应该生成

<script data-turbolinks-track="true" src="/assets/modernizr.js?body=1"></script>

在生产中,我的stylesheet_link_tag很好,可以链接到/assets/目录.

In production, my stylesheet_link_tags are fine, linking to the /assets/ directory.

为什么在生产环境中javascript_include_tag链接到/javascripts而不是/assets,我该如何解决?

Why is the javascript_include_tag linking to /javascripts instead of /assets in production, and how can I fix it?

推荐答案

AssetUrlHelper的用法说明之一表明它将生成/javascripts/网址 就像您看到的一样:

One of the usage statements for AssetUrlHelper indicates it will produce /javascripts/ urls like what you are seeing:

#asset_path应用程序",键入::javascript#=>/javascripts/application.js

# asset_path "application", type: :javascript # => /javascripts/application.js

(从asset_url_helper.rb第117行-[ 1 ])

(from asset_url_helper.rb line 117 - [1])

该代码看起来只有在缺少预编译资产的情况下才可以访问 因此您的资产编译似乎无法正常工作(通常是我的部署 发生这种情况时会失败,所以也许您甚至没有解雇.

This code looks like it can only be reached if the precompiled asset is missing so it would appear that your asset compilation is not working (my deployments usually fail when that happens, so maybe yours isn't even firing).

相同的asset_url_helper.rb调用/javascripts/部分"extname", 使用以下映射了解如何生成名称:

The same asset_url_helper.rb calls the /javascripts/ part 'extname' and uses the following map to know how to generate the name:

 # Maps asset types to public directory.
  ASSET_PUBLIC_DIRECTORIES = {
    audio:      '/audios',
    font:       '/fonts',
    image:      '/images',
    javascript: '/javascripts',
    stylesheet: '/stylesheets',
    video:      '/videos'
  }

新的Rails 4应用程序在config/environments/production.rb中具有此功能

A new Rails 4 app has this in the config/environments/production.rb

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

这似乎与您看到的行为相符.

which seems to match the behavior you are seeing.

这篇关于javascript_include_tag Rails 4生成"/javascripts/"而不是"/资产"在生产中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆