将rails app部署到Heroku后,没有下拉菜单

时间:2013-08-10 19:08:21

标签: ruby-on-rails ruby heroku

将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' %>

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

1 个答案:

答案 0 :(得分:3)

在(大多数)生产设置中,只有public/assets中的文件可以直接在linkscript标记中使用。

当您推送到Heroku时,它会通过将app/assets/javascripts/application.js中所需的所有javascript文件合并并压缩到application.js的单个文件中来预编译public/assets/application-xxxxxx.js。单个文件(例如jquery.js)不可用。因此,建议使用

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

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

但是,如果您坚持在application.js中手动包含jquery而不需要它,则可以将其添加到config.assets.precompile

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

注意:一位朋友告诉我,Heroku在预编译期间没有读取production.rb。如果是这种情况,请尝试将上述内容添加到config/application.rb。)< / p>

当您推送到Heroku并预编译资产时,您应该看到

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

在Heroku上,脚本标签现在应该看起来像

<script src="/assets/jquery-36fecc5eda81b43bdf4f92ce2d874df2.js"></script>