簡體   English   中英

使用bootstrap_form gem時遇到問題 - 無法找到文件'rails_bootstrap_forms'錯誤

[英]Trouble using bootstrap_form gem - couldn't find file 'rails_bootstrap_forms' error

我正在嘗試使用bootstrap_form~> 2.0.1 gem(請參閱https://github.com/bootstrap-ruby/rails-bootstrap-forms ),但它讓我適合。 我按照github頁面上的說明安裝,將其添加到我的Gemfile中:

gem 'bootstrap_form', '~> 2.0.1'

我運行了bundle install。 然后我將它添加到我的application.css.scss文件中:

 *= require_self
 *= require rails_bootstrap_forms
 *= require_tree .

但是,當我嘗試運行我的應用程序時,我得到:

找不到文件'rails_bootstrap_forms'(在/path/to/my/app/assets/stylesheets/application.css.scss:12)

我顯然錯過了一些東西。 我檢查了lib / assets /和vendor / assets / stylesheets /但是那里什么都沒有。 同樣,app / assets / stylesheets /中沒有任何內容。

什么是軟糖?

我有一些麻煩,部分(我認為),因為他們重命名了寶石。 對我來說似乎有什么不同之處在於讓它從github獲取最新的gem,將它放入我的Gemfile:

gem 'bootstrap_form', github: 'bootstrap-ruby/rails-bootstrap-forms'

我使用bootstrap-sass,所以我不想亂用application.css,所以我確保以下import語句在application.css.scss中,如下所示:

@import "bootstrap";
@import 'rails_bootstrap_forms';

記住在進行這些更改后重新啟動服務器也很重要!

您必須在app/assets/stylesheets創建文件rails_bootstrap_form.css

.rails-bootstrap-forms-date-select,
.rails-bootstrap-forms-time-select,
.rails-bootstrap-forms-datetime-select {
  select {
    display: inline-block;
    width: auto;
  }
}
.rails-bootstrap-forms-error-summary {
  margin-top: 10px;
}

我遇到了這個問題,發現我錯誤地將Gemfile條目輸入為bootstrap-form 我把它更正為bootstrap_form ,一切都很順利。

你安裝了Bootstrap嗎? 看起來這是bootstrap_form的要求,但它不作為gem中的依賴項包含在內,這意味着您需要手動安裝Bootstrap。

一種流行的方法是使用twitter-bootstrap-rails gem 安裝它的最簡單方法是在gemfile中包含gem "twitter-bootstrap-rails" ,然后運行

$ bundle install

其次是

rails generate bootstrap:install static ,它應該將所需的CSS文件添加到assets文件夾中。

我得到了同樣的錯誤,所以我從application.css.scss取出了*= require rails_bootstrap_forms ,並且能夠編譯和部署而沒有任何錯誤。

盡管SO的警告不要回應其他答案,但我將通過解釋為什么你需要在app/assets/stylesheets創建一個rails_bootstrap_forms.css文件來增強Thomas Geider的答案。

如果您查看rails-bootstrap-forms Github,您會發現它們有一個rails_bootstrap_forms.css文件。 README沒有告訴你這個,但是這個css文件需要在/app/assets/stylesheets

這是文件:

https://github.com/bootstrap-ruby/rails-bootstrap-forms/blob/master/app/assets/stylesheets/rails_bootstrap_forms.css

暫無
暫無

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

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