Javascript和Heroku。即使脚本在本地运行,脚本也不在服务器上运行

时间:2012-07-03 19:46:03

标签: javascript ruby-on-rails-3 heroku

我有一个带有Slidedeck jquery插件的网站。当我在本地服务时它工作得很好,看起来很棒。然而,在我把它推到Heroku之后,它根本不起作用。

我使用sprockets包含了所有文件,并且我还使用了一个处理主题的gem(themes_for_rails)。我在config中有一个初始化器:

 ThemesForRails.config do |config|
  # themes_dir is used to allow ThemesForRails to list available themes. It is not used to resolve any paths or routes.
  config.themes_dir = ":root/app/assets/themes"

  # assets_dir is the path to your theme assets.
  config.assets_dir = ":root/app/assets/themes/halo"

  # views_dir is the path to your theme views
  config.views_dir =  ":root/app/views/themes/halo"

  # themes_routes_dir is the asset pipeline route base. 
  # Because of the way the asset pipeline resolves paths, you do
  # not need to include the 'themes' folder in your route dir.
  #
  # for example, to get application.css for the default theme, 
  # your URL route should be : /assets/default/stylesheets/application.css
  config.themes_routes_dir = "assets"
end

这是我的application.js:

//= require jquery
//= require jquery_ujs
//= require_tree .
//= require_tree ../themes/halo/javascripts

也许我的问题是我在Heroku中使用相对路径。但是,我不确切知道如何做绝对路径。

1 个答案:

答案 0 :(得分:1)

之前我没有使用过Slidedeck库,但是这里有一些需要考虑的内容来缩小你的bug来源:

  • Javascript错误输出。在Heroku上加载应用程序中的控制台。基本的Javascript是否有效?如果没有,有些东西可能正在吃你的错误 - 我之前已经看到过这种情况,但我无法找到究竟是什么原因造成的。

  • 幻灯片加载实际上存在问题吗?如果它包含在一个类中(比如jQuery如何包装在jQuery类中),你能在控制台中引用该类吗?

  • Heroku上的相对路径应该没问题......但我注意到这一行:

    // = require_tree ../ themes / halo / javascripts

    你要求相当于app/assets/themes/halo/javascripts。是对的吗?为什么不使用javascripts文件夹?如果您在此文件夹中也有css和图像,则可以将它们拆分为各自的app/assets/子文件夹,这是确定无疑的。 (我的队友告诉我,这不是或不应该是必要的,但我发现它可以在一两个例子中帮助我。)

  • 是否有任何控制台错误推送到Heroku与资产预编译失败有关?他们有一个专门的页面来解决这个错误。

相关问题