部署后将自定义CSS和Javascript链接到Rails

0bs*_*r07 1 css ruby-on-rails heroku ruby-on-rails-3 twitter-bootstrap

我有一个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">
Run Code Online (Sandbox Code Playgroud)

我用Google搜索了所有我想要的是Heroku指南,我对资产管道事情感到困惑!我也运行了这个命令:

bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

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

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

当我跑的时候

Heroku Logs

这就是我对CSS和JS文件进行了一些严肃的无路由匹配,如下所示:

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

这只是一行,我为其他文件获得了更多这些,并预先生成了loggs行

任何帮助将不胜感激!

PS:

我试过了

       <%= stylesheet_link_tag "bootstrap" %>
<%= stylesheet_link_tag "bootstrap-responsiv" %>
 <%= stylesheet_link_tag "bootswatch", "font-awesome.css" %>
Run Code Online (Sandbox Code Playgroud)

我收到了很多错误,而且在heroku上它说抱歉出了问题

Raj*_*n_R 5

在application.rb(config/application.rb)中

    # Enable the asset pipeline
    config.assets.enabled = true
Run Code Online (Sandbox Code Playgroud)

在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
Run Code Online (Sandbox Code Playgroud)

那么你应该包括你所有的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)
Run Code Online (Sandbox Code Playgroud)

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

     $ RAILS_ENV=production bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

然后 $ heroku restart

它应该工作.

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