1

我有一个 Rails 应用程序,它的 css 和 js 链接在本地运行良好,因为我使用过:

    <link href="assets/bootstrap.css" rel="stylesheet">
    <link href="assets/bootstrap-responsive.css" rel="stylesheet">
    <link href="assets/font-awesome.css" rel="stylesheet">
    <link href="assets/bootswatch.css" rel="stylesheet">

我在谷歌上搜索的不仅仅是这个Heroku 指南,我对资产管道的事情感到非常困惑!我也运行了这个命令:

bundle exec rake assets:precompile

并且它确实在指南中提到的公共目录中创建了一些文件:

现在在 Heroku 上,一切都很简单,没有设计,没有 Css 和 JS。

当我跑步时

Heroku 日志

这就是我为 CSS 和 JS 文件得到的一些严重的 NO Route Match,如下所示:

2013-06-10T10:06:28.184255+00:00 app[web.1]: ActionController::RoutingError (没有路由匹配 [GET] "/assetscv.png"):

这只是一行,我为其他文件获得了更多这些,以及预先生成的日志行

任何帮助将不胜感激谢谢!

PS:

我试过了

       <%= stylesheet_link_tag "bootstrap" %>
<%= stylesheet_link_tag "bootstrap-responsiv" %>
 <%= stylesheet_link_tag "bootswatch", "font-awesome.css" %>

我遇到了一堆错误,在 heroku 上它说抱歉出了点问题

4

1 回答 1

5

在 application.rb(config/application.rb)

    # Enable the asset pipeline
    config.assets.enabled = true

在 production.rb 文件(config/environments/production.rb)之后这样做

      # Settings specified here will take precedence over those in config/application.rb

      # Code is not reloaded between requests
      config.cache_classes = true

      # Full error reports are disabled and caching is turned on
      config.consider_all_requests_local       = false
      config.action_controller.perform_caching = true

      # Disable Rails's static asset server (Apache or nginx will already do this)
      #config.serve_static_assets = true

      # Compress JavaScripts and CSS
      config.assets.compress = true

      # Don't fallback to assets pipeline if a precompiled asset is missed
      config.assets.compile = false

      # Generate digests for assets URLs
      config.assets.digest = true

那么你应该像这样包含所有的js和css,

     config.assets.precompile += %w(jquery.js jquery_ujs.js PIE.js check_list.js dom-drag.js jquery-1.4.2.min.js jquery-1.7.1.min.js jquery-1.8.3.js jquery-ui.js jquery.accordion.js jquery.corner.js jquery.countdown.js jquery.dimensions.js jquery.masonry.min.js jquery.tinycarousel.min.js jquery.validationEngine-en.js jquery.validationEngine.js questionnaire.js prototype.js users.js)

     config.assets.precompile += %w(ie7.css ie8.css about_us.css admin_menu.css blog.css default.ultimate.css designer_directory.css designer_directorynew.css drop.css greenstore.css menu.css MenuMatic_dev.css message_view.css product.css setting1.css style1.css styles.css validationEngine.jquery.css)

之后使用此命令进行预编译

     $ RAILS_ENV=production bundle exec rake assets:precompile

然后$ heroku restart

它应该工作。

有关更多详细信息,请阅读http://guides.rubyonrails.org/asset_pipeline.html

于 2013-06-10T11:32:23.210 回答