jPlayer在本地使用Rails应用程序,但在部署到Heroku时则不行

时间:2012-11-06 14:23:38

标签: jquery ruby-on-rails-3 layout heroku jplayer

我让jPlayer音频播放器在本地工作正常,但是当我部署到Heroku时,它不再有效,我在Chrome的控制台中收到以下错误:

Uncaught TypeError: Object [object Object] has no method 'jPlayer' 

这是我的application.html.erb布局中jPlayer的Javascript:

  <script type="text/javascript">
  $(document).ready(function(){
    $("#jquery_jplayer_1").jPlayer({
      ready: function () {
        $(this).jPlayer("setMedia", {
             mp3: "http://test.com/song.mp3",
          // m4a: "http://www.jplayer.org/audio/m4a/Miaow-07-Bubble.m4a",
          // oga: "http://www.jplayer.org/audio/ogg/Miaow-07-Bubble.ogg"
        });
      },
      swfPath: "/javascriptipts",
      supplied: "mp3, m4a, oga"
    });
  });

我注意到脚本的包含方式似乎与Heroku的工作方式不同。对于我的本地实例(有效),包含的脚本在源代码中如下所示:

   <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/bootstrap-responsive.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/bootstrap.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/calls.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/jplayer.blue.monday.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/main.css?body=1" media="all" rel="stylesheet" type="text/css" />
   <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-alert.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-button.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-carousel.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-collapse.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-dropdown.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-popover.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-scrollspy.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tab.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tooltip.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-transition.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-typeahead.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap.min.js?body=1" type="text/javascript"></script>
<script src="/assets/calls.js?body=1" type="text/javascript"></script>
<script src="/assets/custom.js?body=1" type="text/javascript"></script>
<script src="/assets/google-code-prettify/prettify.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.jplayer.min.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>

在Heroku上,jPlayer不工作,由于某种原因,加载的脚本在源代码中看起来像这样:

<link href="/assets/application-7d9d2071282c290d4dd4bb767188d15f.css" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/application-679ead39cc620e8b5be4723def8305ce.js" type="text/javascript"></script>

以下是我在application.html.erb布局中包含它们的方法:

<%= stylesheet_link_tag    "application", :media => "all" %>
<%= javascript_include_tag "application" %>

任何人都有任何想法可能导致这种情况以及如何解决这个问题?

提前致谢!

1 个答案:

答案 0 :(得分:1)

我想出来了,虽然我不完全确定它为什么会发生。

我不得不删除&#39; bootstrap-popover.js&#39;来自&quot;资产/ javascripts&#39;的文件。它导致了本地的以下错误(如上所述),这使我把2和2放在一起。

"Uncaught TypeError: Cannot read property "Constructor" of undefined

不确定为什么它在本地工作尽管出现此错误?如果有人知道,我很乐意了解原因。