簡體   English   中英

Rails 4引導程序無法加載

[英]Rails 4 Bootstrap Doesn't Load

我真的要走了,所以我希望有人能在這里幫助我。

我已遵循本文檔(以及8個教程) https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails

執行完此操作並嘗試將getbootstrap網站上的components / examples頁面上的導航欄添加到我的appliaction.html.erb文件后,我確實看到頁面上的文本加載,但是我從未將任何CSS應用於該頁面。

它根本不起作用,我想盡辦法解決這個問題。

UPDATE

我有https://github.com/KR0SIV/learning-bootstrap

Application.css.scss

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require_tree .
 *= require_self
 */
@import "bootstrap-sprockets";
@import "bootstrap";

然后,只是為了查看是否可行,我只是將示例中的導航欄添加到我的項目application.html.erb文件中

<!DOCTYPE html>
<html>
<head>
  <title>LearningBootstrap</title>

</head>
<body>
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Brand</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>


<%= yield %>

</body>
</html>

所以首先。 您的項目中有多個應用程序樣式表。 application.cssapplication.css.scss 刪除application.css,然后將另一個重命名為application.scss

比刪除以下幾行:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require_tree .
 *= require_self
 */

Bootstrap gem自述文件寫道:

然后,從Sass文件中刪除所有* = require和* = require_tree語句。 而是使用@import導入Sass文件。

不要在Sass中使用* = require,否則您的其他樣式表將無法訪問Bootstrap mixins和變量。

這可能是您的問題,因為您說它找不到sass變量。

要導入所有其他CSS文件,請添加以下行以刪除引導程序導入:

@import '**/*';

這將遞歸添加所有CSS文件。

當然,您必須將樣式表添加到HTML模板中。

只需使用默認的Rails之一:

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

重要! Bootstrap 4仍在開發中,目前僅是Alpha版本。 我建議您將Bootstrap 3用於生產應用程序。 但是,如果只是為了學習,那就太好了。

如果有官方可用的寶石,我不建議您使用諸如twitter-bootstrap-rails之類的第三方寶石。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM