2016-09-25 56 views
6

我是新來的紅寶石,我想包括bootstrap 4.0.0.alpha4到rails 5.0.0。 我已經安裝了gest bootstrap,bootstrap-sass,autoprefixer-rails,我甚至在application.css.sass中使用了@import「bootstrap」,但仍然沒有在頁面上獲得bootstrap。我試圖實施自舉設計的觀點。我甚至在不同的項目上嘗試過,但沒有一個能起作用。任何幫助,將不勝感激。謝謝。
代碼如下所示。 寶石文件如何實現引導4和導軌5

source 'https://rubygems.org' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '~> 5.0.0' 
# Use postgresql as the database for Active Record 
gem 'pg', '~> 0.18' 
# Use Puma as the app server 
gem 'puma', '~> 3.0' 

gem 'bootstrap' 
gem 'bootstrap-sass' 
gem 'autoprefixer-rails' 

gem 'wdm' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.2' 
# See https://github.com/rails/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 
gem 'turbolinks', '~> 5' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.5' 
# Use Redis adapter to run Action Cable in production 
# gem 'redis', '~> 3.0' 
# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 

group :development, :test do 
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console 
    gem 'byebug', platform: :mri 
end 

group :development do 
    # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 
    gem 'web-console' 
    gem 'listen', '~> 3.0.5' 
    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
    gem 'spring-watcher-listen', '~> 2.0.0' 
end 

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 
+1

[這](https://github.com/twbs/bootstrap- sass/blob/master/README.md)幾乎涵蓋了你需要做的事情。 –

+0

我做到了這一點,但它仍然無法正常工作,我甚至通過直接安裝bootrap.css和bootstrap.min.css幷包含在application.css.sass中來嘗試沒有gems,但仍然無法正常工作。 –

+0

根據https://rubyplus.com/articles/3981-Integrating-Twitter-Bootstrap-4-with-Rails-5鏈輪應該在引導程序4中使用機器人或否則它會給出錯誤文件導入找不到或不可讀 –

回答

3

對於官方參考代碼,包括引導到Rails,看到test/dummy_rails項目框架官方bootstrap-rubygem項目。該項目用於集成測試,因此您知道它可以與項目測試矩陣中的最新版本的Bootstrap gem和任何版本的Ruby/Rails配合使用。

確保這些代碼行(或同等學歷)已被添加到您的Rails項目:

如果您仍然遇到問題,請將完整的源代碼發佈到您的Rails應用程序或足以用作產生問題的Minimal, Complete and Verifiable Example--總有一種可能性是您在本地更改了某些您沒有想過但實際上重要。

1

您可以在https://v4-alpha.getbootstrap.com/下載引導程序文件,然後將它們複製並粘貼到您的資產文件(供應商),然後將其導入到您的應用程序,方法是將其調用到application.js和application.css中,或將其稱爲你調用其他js和css文件的方式。這樣你可以使用boostrap。

+0

非常糟糕的主意。 Rails有它的寶石;/ – Darex1991

+1

@ Darex1991該寶石沒有更新的最新版本 –

+0

ohh那麼它是過時的信息,tnx – Darex1991

2

link和 這裏是我的配置:

的Gemfile:

gem 'compass-rails', '2.0.4' 
gem 'bootstrap-sass', '~> 3.1.1.1' 
gem 'autoprefixer-rails', '6.3.7' 
gem 'sass-rails', '~> 5.0.1' 

配置/初始化/ assets.rb

Rails.application.config.assets.version = '1.0' 
Rails.application.config.assets.paths << Rails.root.join('app', 'assets', 'fonts') 

而且我頂嘴文件樹:

app/assets/stylesheets 
| 
|--components 
| | 
| |--variables, 
| |--mixins and another css/sass files 
| 
|--bootstrap.sass 
|--application.sass 

application.sass:

@import 'bootstrap' 
@import 'components/*' 

bootstrap.sass:

// Core variables and mixins 
@import 'bootstrap/variables' 
@import 'bootstrap/mixins' 

// Reset 
@import 'bootstrap/normalize' 
//@import 'bootstrap/print' 

// Core CSS 
//@import 'bootstrap/scaffolding' 

頭:

= stylesheet_link_tag 'application', media: 'all'

+0

問題是關於bootstrap 4不bootstrap 3 –