【问题标题】:Loading JS in asset pipeline在资产管道中加载 JS
【发布时间】:2012-05-13 03:02:25
【问题描述】:

我刚刚更新了我的网站以使用 jQuery 插件 jquery.raty.min.js

该插件允许用户在完成评论时选择 jQuery 风格的星级评分。

http://www.wbotelhos.com/raty/

在本地主机上一切正常,但是当我部署到“heroku”时,我收到一个错误,甚至无法加载主页!请参阅下面的错误:

 ActionView::Template::Error ('twitter/bootstrap/bootstrap.less' wasn't found.
   (in /app/app/assets/stylesheets/bootstrap_and_overrides.css.less)):
6:     <!--[if lt IE 9]>
7:     <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
8:     <![endif]-->    
9:     <%= stylesheet_link_tag "application", media: "all" %>
10:     <%= javascript_include_tag "application" %>
11:     <%= include_gon %>
12:     <%= csrf_meta_tags %>    
app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb___4184194920936324767_38840920'

在本地主机上一切正常,无需添加要求行,即//= require jquery.raty.min,但在“heroku”上,插件根本不加载。为了修复它,我添加了 require 行,但随后我开始收到网站上每个页面的上述错误。

编辑:

我的 application.js:

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require twitter/bootstrap
//= require bootstrap-tooltip
//= require bootstrap-popover
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap
//= require chosen-jquery
//= require_tree .

我将 jquery.raty.min 的包含放在哪里似乎并不重要。它总是坏掉:)

更新:

我实际上正在使用https://github.com/seyhunak/twitter-bootstrap-rails gem,为了解决这个问题,我需要添加到我的 application.css:

*= bootstrap_and_overrides.css.less 

【问题讨论】:

    标签: jquery ruby-on-rails asset-pipeline assets


    【解决方案1】:

    您需要在应用程序 css 中包含 twitter-bootstrap

    *= require 'twitter/bootstrap'
    

    【讨论】:

    • 谢谢 Yuriry.. 请检查我的编辑
    • 但是你的 application.css 不是 JS 呢
    【解决方案2】:

    在我的 application.css 文件中添加 *= bootstrap_and_overrides.css.less 并不能解决我在 heroku 上使用 twitter-boostrap-rails gem 时遇到的类似问题。您可能需要在 config/application.rb 文件中设置以下内容:

    config.assets.initialize_on_precompile = false
    

    我最初是在以下位置找到的: http://www.simonecarletti.com/blog/2012/02/heroku-and-rails-3-2-assetprecompile-error/

    我还按照 Abram 的建议将 *= bootstrap_and_overrides.css.less 留在了我的 application.css 文件中,现在所有作品都将在 Heroku 上运行。

    【讨论】:

      【解决方案3】:

      试试bundle exec rake assets:precompile

      http://guides.rubyonrails.org/asset_pipeline.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-26
        • 2017-02-06
        • 2012-04-19
        • 1970-01-01
        • 1970-01-01
        • 2014-03-01
        相关资源
        最近更新 更多