在生产中找不到文件“ twitter / bootstrap”

ruby-on-rails CSS

小胖Gil

2020-03-24

我正在使用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上运行。

第3360篇《在生产中找不到文件“ twitter / bootstrap”》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

5个回答
飞云 2020.03.24

将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
宝儿 2020.03.24

只需将其放入您的gemfile

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

BootStrap 2.0中存在无效的CSS,这会导致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
DavaidTony宝儿 2020.03.24

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

config.serve_static_assets = true
猴子村村 2020.03.24

config/environments/production.rb添加此行:

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

我的猜测是它不会添加您的所有资产。

理查德神无Mandy 2020.03.24

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

从GemFile

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

因此,只需将宝石移到任何组之外,就可以了。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android