【问题标题】:Couldn't find file 'twitter/bootstrap' in Production在生产中找不到文件“twitter/bootstrap”
【发布时间】:2012-02-21 06:42:26
【问题描述】:

我正在使用 Twitter 的 Bootstrap 转换为 SCSS 文件。它适用于本地开发,但是当我预编译并推送到 Heroku(使用 Cedar 堆栈)时,我得到了这个:

> Started GET "/" for 74.57.16.130 at 2012-01-28 17:16:36 +0000 
> Processing by StaticPagesController#home as HTML  Rendered
> static_pages/home.html.erb within layouts/application (0.7ms) 
> Completed 500 Internal Server Error in 4ms
> 
>  ActionView::Template::Error (couldn't find file 'twitter/bootstrap'  
> (in /app/app/assets/stylesheets/application.scss.css:11)):
>      8: </head>
>      6:   <%= javascript_include_tag "application" %>
>      4:   <title><%= full_title(yield(:title)) %></title>
>      2: <html>
>      5:   <%= stylesheet_link_tag    "application", :media => "all" %>        
app/views/layouts/application.html.erb:5:in
> `_app_views_layouts_application_html_erb___288948710373692320_32137840'
>      3: <head>    cache: [GET /] miss
> 
>      7:   <%= csrf_meta_tags %>  cache: [GET /favicon.ico] miss

我使用的是 Rails 3.2.0,在我添加 SASS 文件之前,该应用程序一直在 Heroku 上运行。

【问题讨论】:

  • 你能告诉我你的 app/assets/js 文件夹中的 application.css
  • 文件中只有 *= 需要 twitter/bootstrap
  • 感谢大家的帮助。

标签: ruby-on-rails ruby-on-rails-3 heroku asset-pipeline sass


【解决方案1】:

确保在 config/environments/production.rb 中有...

config.serve_static_assets = true

【讨论】:

    【解决方案2】:

    当您在将 rails 应用程序部署到 heroku.com 时看到类似的内容时

    Precompiling assets failed, enabling runtime asset compilation
    ...
    could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port xxxx?
    

    只需将其添加到 config/application.rb

    config.assets.initialize_on_precompile = false
    

    【讨论】:

      【解决方案3】:

      这至少解决了heroku中的问题

      只需降级到 sass-rails 3.1.4

      group :assets do
        gem 'coffee-rails', '~> 3.1.1'
        gem 'uglifier', '>= 1.0.3'
        gem 'sass-rails', '3.1.4'
        gem 'bootstrap-sass', '~> 2.0.2'
      end
      

      【讨论】:

        【解决方案4】:

        你在使用宝石吗?确保您的 gem 不属于资产组并且可以在生产环境中访问。

        来自 GemFile

        # Gems used only for assets and not in production environments by default.
        

        所以只要将 gem 移出任何组就可以了。

        【讨论】:

        • 据我了解,当我运行预编译命令时,我想它会将所有 SASS 文件编译成一个 CSS 文件。不是这样吗? (我对此很陌生,但很喜欢)
        • 我认为您正在使用的 gem 中的 SASS 没有被预编译,我也不确定。
        • 我想你已经找到了答案。非常感谢。
        • @mike 你是上帝!如果我能投票 1000 次就好了。 _/_
        【解决方案5】:

        把它放在你的gemfile中

        gem "twitter-bootstrap-rails", "~> 2.0rc0"
        

        There's invalid CSS in BootStrap 2.0 导致 SCSS 编译失败

        您可以通过查看

        的输出来验证这一点
        git push heroku master 
        

        您应该会看到一些错误,例如:

        -----> Preparing app for Rails asset pipeline
               Running: rake assets:precompile
               rake aborted!
               Invalid CSS after "...er-radius:0 \0/": expected expression (e.g. 1px, bold), was ";}"
               (in /tmp/build_1k8ugei34dpcw/app/assets/stylesheets/application.css)
        
               Tasks: TOP => assets:precompile:primary
               (See full trace by running task with --trace)
               Precompiling assets failed, enabling runtime asset compilation
               Injecting rails31_enable_runtime_asset_compilation
               Please see this article for troubleshooting help:
               http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
        

        【讨论】:

          【解决方案6】:

          config/environments/production.rb 中添加这一行:

          config.assets.precompile = [/^[-_a-zA-Z0-9]*\..*/]

          我的猜测是它没有添加你所有的资产。

          【讨论】:

          • 我回家后试试这个。谢谢你。这被认为是常规(最佳)做法吗?
          • @JohnCho 我不知道。我只知道当我添加更多的 javascript 文件时,我在生产中的编译器完全忽略了它们,我不得不添加这一行。
          • 我今天早上试了一下,修改了文件,运行了预编译,然后推送到 heroku,一切都很好,但我在日志中仍然有同样的错误。 =(
          • @JohnCho twitter/bootstrap 是什么?那是一个文件吗?是文件夹吗?
          • 这是一个 SCSS 文件,它可以按顺序导入所有其他 SCSS 文件(它在开发中应该可以正常工作)。今晚我将尝试通过通配符导入,看看它在生产中是否有效,然后我会知道它是否与事物的导入方式有关。我在这里有点抓住稻草了。
          猜你喜欢
          • 2015-09-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多