0

将我的 rails 应用程序部署到 heroku 后,没有下拉菜单!

在本地运行时,我的源代码如下所示:

        <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.core.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.theme.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.accordion.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.menu.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.autocomplete.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.button.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.datepicker.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.resizable.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.dialog.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.progressbar.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.selectable.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.slider.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.spinner.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.tabs.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.tooltip.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.base.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/jquery.ui.all.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/foundation_and_overrides.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/admins.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/associates.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/custom.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/dasharea.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/database.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/members.css?body=1" media="screen" rel="stylesheet" />
    <link href="/assets/sessions.css?body=1" media="screen" rel="stylesheet" />
        <script src="/assets/vendor/custom.modernizr.js?body=1"></script>
        <meta content="authenticity_token" name="csrf-param" />
    <meta content="anbyACcBlOI2Zpa9E2TImosNiBYN5KFTC8heYI1TE+I=" name="csrf-token" />

        <script src="/assets/jquery.js?body=1"></script>
        <script src="/assets/jquery.ui.core.js?body=1"></script>
    <script src="/assets/jquery.ui.widget.js?body=1"></script>
    <script src="/assets/jquery.ui.accordion.js?body=1"></script>
    <script src="/assets/jquery.ui.position.js?body=1"></script>
    <script src="/assets/jquery.ui.menu.js?body=1"></script>
    <script src="/assets/jquery.ui.autocomplete.js?body=1"></script>
    <script src="/assets/jquery.ui.button.js?body=1"></script>
    <script src="/assets/jquery.ui.datepicker.js?body=1"></script>
    <script src="/assets/jquery.ui.mouse.js?body=1"></script>
    <script src="/assets/jquery.ui.draggable.js?body=1"></script>
    <script src="/assets/jquery.ui.resizable.js?body=1"></script>
    <script src="/assets/jquery.ui.dialog.js?body=1"></script>
    <script src="/assets/jquery.ui.droppable.js?body=1"></script>
    <script src="/assets/jquery.ui.effect.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-blind.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-bounce.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-clip.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-drop.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-explode.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-fade.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-fold.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-highlight.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-pulsate.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-scale.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-shake.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-slide.js?body=1"></script>
    <script src="/assets/jquery.ui.effect-transfer.js?body=1"></script>
    <script src="/assets/jquery.ui.progressbar.js?body=1"></script>
    <script src="/assets/jquery.ui.selectable.js?body=1"></script>
    <script src="/assets/jquery.ui.slider.js?body=1"></script>
    <script src="/assets/jquery.ui.sortable.js?body=1"></script>
    <script src="/assets/jquery.ui.spinner.js?body=1"></script>
    <script src="/assets/jquery.ui.tabs.js?body=1"></script>
    <script src="/assets/jquery.ui.tooltip.js?body=1"></script>
    <script src="/assets/jquery.ui.all.js?body=1"></script>
        <script src="/assets/jquery_ujs.js?body=1"></script>

在 Heroku 中,它看起来像这样:

<script src="/javascripts/jquery.js"></script>
<script src="/javascripts/jquery.ui.all.js"></script>
<script src="/javascripts/jquery_ujs.js"></script>

但是没有找到 Heroku 中的链接!

出于特殊原因,我手动将 jquery 包含在我的脑海中,如下所示:

<%= javascript_include_tag 'jquery' %>
<%= javascript_include_tag 'jquery.ui.all' %>
<%= javascript_include_tag 'jquery_ujs' %>

这是事情失败的原因吗?如何在不从头部移除这些的情况下修复它?

4

1 回答 1

3

In (most) production setups, only the files in public/assets are available for use directly in link or script tags.

When you push to Heroku, it precompiles app/assets/javascripts/application.js by merging and compressing all javascript files required in application.js into a single file at public/assets/application-xxxxxx.js. Individual files, such as jquery.js, are not available. Therefore, it's recommended to use

<!-- HTML -->
javascript_include_tag 'application'

// inside app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs

However, if you insist on including jquery manually without requiring it in application.js, you can add it to config.assets.precompile.

# config/environments/production.rb
config.assets.precompile += ['jquery.js', 'jquery_ujs.js']

(Note: A friend told me that Heroku doesn't read production.rb during precompilation. If that's the case, try adding the above to config/application.rb instead.)

When you push to Heroku and precompile your assets, you should see

$ rake assets:precompile
I, []  INFO -- : Writing public/assets/jquery-36fecc5eda81b43bdf4f92ce2d874df2.js
I, []  INFO -- : Writing public/assets/jquery_ujs-02181b3e64cd9e4e8548cad033516231.js

On Heroku, the script tags should now look like

<script src="/assets/jquery-36fecc5eda81b43bdf4f92ce2d874df2.js"></script>
于 2013-08-10T21:52:32.560 回答