Reputation: 1
I have tried everything and I just cant get my navbar in bootstrap to work. I am using a up to date version of ruby and rails version
I have the gems the github tells me to put in my code
and its says that they are being used
I changed my application file from application.css to a scss file and got rid of all the require statements.
I updated my application.js file the way they told me to.
but when I try and put this boostrap header in my file
I end up with this
instead of this
If anyone could help it would be appreciated. I have done everything I could think of.
Upvotes: 0
Views: 1517
Reputation: 1036
I recently done a project in ruby on rails with Bootstrap 4 beta 2, here are my setup:
Gemfile
gem 'jquery-ui-rails', '~> 5.0', '>= 5.0.5'
gem 'bootstrap', '~> 4.0.0.beta2'
gem 'jquery-rails', '~> 4.3', '>= 4.3.1'
gem 'font-awesome-rails'
app/assets/javascripts/application.js (The sequence are important)
//= require jquery3
//= require popper
//= require rails-ujs
//= require jquery-ui
//= require_tree .
//= require bootstrap-sprockets
assets/stylesheets/application.scss
@import "bootstrap";
@import "font-awesome";
For more details, go visit bootstrap-sass gem
Generate new rails app rails new bootstrap4test
bundle install
Scaffold a simple blog with text rails g scaffold Blog content:text
Database Migrate rails db:seed && rails db:migrate
Add gem into Gemfile
gem 'bootstrap-sass', '~> 3.3.7' gem 'sass-rails', '>= 3.2'
rename app/assests/stylesheets/application.css
to .scss
remove everything in the application.scss
and add these
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables" @import "bootstrap-sprockets"; @import "bootstrap";
Now, add another gem gem 'jquery-rails'
into your Gemfile
bundle install
in app/assets/javascripts/application.js
add 2 lines
//= require jquery //= require bootstrap-sprockets
Your application.js
should look like this
//= require jquery
//= require bootstrap-sprockets
//= require rails-ujs
//= require turbolinks
//= require_tree .
Tested on Mac, ruby: 2.4.2
, rails: 5.1.4
Upvotes: 2
Reputation: 6564
You should need to include @import "bootstrap-sprockets"
before @import "bootstrap"
. do not know if rails-ujs
includes both but, you might also want to require jquery
and jquery_ujs
inside application.js
file.
assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
assets/stylesheets/application.scss
@import "bootstrap-sprockets";
@import "bootstrap";
views/layouts/application.html.erb
<%= javascript_include_tag 'application' %>
<%= stylesheet_link_tag 'application', media: 'all' %>
below is an excerpt from my working rails+bs setup.
Upvotes: 0