I am trying to load bootstrap styles into a rails app using the bootstrap-sass gem and its documentation here, but when I copy examples from the bootstrap documentation the styles do not load properly. Following that documentation, it asks you to put the statements:
//= require jquery
//= require bootstrap-sprockets
inside of app/assets/javascripts/application.js, however this file does not get created in that directory when I create a new app, instead it is in app/javascript/packs/application.js. I tried placing those statements into both files, after creating the second file mentioned and still the styles were not rendering properly.
This is what the navbar I am attempting to add looks like on the site:
And these are the files that were changed following the tutorial:
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# 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.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bootstrap-sass'
gem 'jquery-rails'
gem 'sassc-rails', '>= 2.1.0'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# 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
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
app/assets/stylesheets/application.scss:
#import "bootstrap-sprockets";
#import "bootstrap";
app/assets/javascripts/application.js:
//= require jquery
//= require bootstrap-sprockets
app/javascript/packs/application.js:
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
require("#rails/ujs").start()
require("turbolinks").start()
require("#rails/activestorage").start()
require("channels")
//= require jquery
//= require bootstrap-sprockets
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
navbar html from documentation:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
What is strange about this problem is that some bootstrap styles will load and others will not. For example, the bg-primary class is loaded but the bg-dark and bg-light are not, and this problem is still present when I make a new rails app and follow the tutorial again. Let me know what I am missing from this tutorial or if there is anything else that is needed to see to solve the issue.
If you are looking for bootstrap for rails 6 then, this will do.
Related
After trying to upgrade my rails app from asset pipeline to the webpacker my modals will no longer pop up. I do not get any errors on initial load of the page or when I click on the modal button. However, if I run $('#edit').modal('show') in the console twice I get these errors:
$('#edit').modal('show')
bootstrap.esm.js:187 Uncaught TypeError: BACKDROP: Option "rootElement" provided type "null" but expected type "element".
at bootstrap.esm.js:187
at Array.forEach (<anonymous>)
at typeCheckConfig (bootstrap.esm.js:181)
at Backdrop._getConfig (bootstrap.esm.js:2856)
at new Backdrop (bootstrap.esm.js:2792)
at Modal._initializeBackDrop (bootstrap.esm.js:3117)
at new Modal (bootstrap.esm.js:2974)
at HTMLDivElement.<anonymous> (bootstrap.esm.js:3359)
at Function.each (jquery.js:328)
at jQuery.fn.init.each (jquery.js:168)
(anonymous) # bootstrap.esm.js:187
typeCheckConfig # bootstrap.esm.js:181
_getConfig # bootstrap.esm.js:2856
Backdrop # bootstrap.esm.js:2792
_initializeBackDrop # bootstrap.esm.js:3117
Modal # bootstrap.esm.js:2974
(anonymous) # bootstrap.esm.js:3359
each # jquery.js:328
each # jquery.js:168
jQueryInterface # bootstrap.esm.js:3358
(anonymous) # VM58:1
$('#edit').modal('show') ## if I enter this again I get a different error
bootstrap.esm.js:3278 Uncaught TypeError: Cannot read property 'show' of undefined
at Modal._showBackdrop (bootstrap.esm.js:3278)
at Modal.show (bootstrap.esm.js:3030)
at HTMLDivElement.<anonymous> (bootstrap.esm.js:3369)
at Function.each (jquery.js:328)
at jQuery.fn.init.each (jquery.js:168)
at jQuery.fn.init.jQueryInterface [as modal] (bootstrap.esm.js:3358)
at <anonymous>:1:12
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use jQuery as the JavaScript library
gem 'jquery-rails'
# bootstrap
gem 'bootstrap', '~> 4.5.2'
gem 'stripe', git: 'https://github.com/stripe/stripe-ruby'
# Adds Sendgrid
gem 'sendgrid-ruby'
# Adds Twilio
gem 'twilio-ruby', '~> 5.52.0'
# Adds Datatables
gem 'jquery-datatables'
# Dependency for boostrap datetimepicker
gem 'momentjs-rails', '>= 2.9.0'
# Adds DateTimePicker
gem 'bootstrap3-datetimepicker-rails', '~> 4.15.35'
# Adds input field masking
gem 'jquery_mask_rails', '~> 0.1.0'
# HTTP request gem
gem 'faraday'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
group :development, :test do
# Debugging tools
gem 'pry'
# Testing framework
gem 'rspec-rails', '~> 5.0.0'
gem 'selenium-webdriver', '~> 3.142', '>= 3.142.7'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :test do
# Testing frontend integration
gem 'capybara'
# Adds ability to open page during testing
gem 'launchy'
# Testing coverage
gem 'simplecov', require: false
# Disallow API calls during testing
gem 'webmock'
# Make inital API call and save as fixtures
gem 'vcr'
# Generate fixtures for testing
gem 'factory_bot_rails'
gem 'faker'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
app/javascripts/pack/application.rb
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
import Rails from "#rails/ujs"
import * as ActiveStorage from "#rails/activestorage"
import "channels"
import "datatables.net-bs4"
import "#fortawesome/fontawesome-free/css/all"
import "moment"
import "bootstrap"
import "datetimepicker"
import "jquery-mask-plugin"
Rails.start()
ActiveStorage.start()
global.$ = jQuery;
config/webpack/environment.rb
const { environment } = require('#rails/webpacker')
const webpack = require('webpack')
environment.plugins.append('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
'window.Tether': 'tether',
Popper: ['popper.js', 'default'],
ActionCable: 'actioncable',
})
)
module.exports = environment
View
<i class="fas fa-edit"></i>
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="Edit" aria-hidden="true" >
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
Some form stuff
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<%= f.submit "Save", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
</div>
app/assets/stylesheets/application.scss
/* Load Bootstrap Libraries */
#import 'bootstrap';
/* Load Datatables */
#import "datatables";
/* Load Datetime picker */
#import 'bootstrap-datetimepicker';
Ben Trewern was right! I removed all my front-end gems from the Gemfile and added it to yarn and fixed the issue. Thanks.
I am trying to implement bootstrap to my app and having issues when I try to implement some modals from bootstrap.
Created my app with using following command;
rails new HR-app -J -C --database=postgresql
My gem file
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.2', '>= 6.0.2.2'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails', '~> 4.0'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# 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'
gem 'rspec-rails', '~> 4.0'
gem 'webpacker', '~> 5.1', '>= 5.1.1'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
environment.js file
const { environment } = require('#rails/webpacker')
const webpack = require('webpack')
environment.plugins.append('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
)
module.exports = environment
application.scss file
#import "bootstrap/scss/bootstrap";
application.js file
import 'bootstrap'
console.log('Hello World from Webpacker')
example I took from bootstrap and index file of my scaffold;
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
And this is how it looks;
It is not desired look of modal and also it is no functional (no error). You can see the live demo of the modal here. getbootstrap.com/docs/4.0/components/modal –
How can I implement the modal as live demo from bootstrap.
Any help will be appreciated!
Thanks :)
I have seen this question asked on this site several times as it seems to be a common problem. Unfortunately none of those solutions worked for me. Below is be my code. This started after I installed Bootstrap on my Ruby on Rails app so I assume there is either a bug or I missed something.
My Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'duktape'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# 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', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bootstrap-sass'
gem 'jquery-rails'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :production do
gem 'pg'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
My application.js:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require bootstrap-sprockets
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
My application.html.erb file which contains my Navbar:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
<title>Website</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application.css" %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<!-- Navigation -->
<div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="#page-top">Alex Ross</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<div class="nav-link">
<%= link_to 'Education/Experience', root_path(anchor: 'Education') %>
</div>
</li>
<li class="nav-item">
<div class="nav-link">
<%= link_to 'Projects', root_path(anchor: 'Projects') %>
</div>
</li>
<li class="nav-item">
<div class="nav-link">
<%= link_to 'Skills', root_path(anchor: 'Skills') %>
</div>
</li>
<li class="nav-item">
<div class="nav-link">
<%= link_to 'Certifications', root_path(anchor: 'Certifications') %>
</div>
</li>
<li class="nav-item">
<div class="nav-link">
<%= link_to 'Contact', root_path(anchor: 'Contact') %>
</div>
</li>
</ul>
</div>
</div>
</nav>
</div>
<%= yield %>
</body>
</html>
My application.scss file:
#import "bootstrap-sprockets";
#import "bootstrap";
body {
margin: auto;
max-width: 800px;
padding-top: 65px;
}
a:link {
color: white;
}
a:hover {
color: white;
}
a:visited {
color:white;
}
#Intro a:link { color:black; }
#Intro a:visited { color: black; }
#Intro a:hover { color: black; }
#Intro a:active { color: black; }
In your application.scss file:
#import "bootstrap";
body {
margin: auto;
max-width: 800px;
padding-top: 65px;
}
a:link {
color: white;
}
a:hover {
color: white;
}
a:visited {
color:white;
}
Or create new file "main.sccs":
body {
margin: auto;
max-width: 800px;
padding-top: 65px;
}
a:link {
color: white;
}
a:hover {
color: white;
}
a:visited {
color:white;
}
And ... add import to "application.sccs" > #import "main";
Maybe error with gem.
Install gems in Gemfile:
css
gem 'bootstrap', '~> 4.1.3'
gem 'jquery-rails'
And write in terminal "bundle i".
It works now! I removed duktape from my gemfile, installed nodejs on my computer, and then rearranged application.js to look like this:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .
I've added to gemfile, bundle installed and bundle updated twitter-bootstrap-rails gem and all of the dependency gems that i need as per here, yet none of the styles in my layout file a rendering? Can anyone see what I'm doing wrong or perhaps whether i'm missing an important require somewhere?
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use postgresql as the database for Active Record
gem 'pg'
# 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.1.0'
# 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 following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'devise'
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'rspec-rails'
end
group :test do
gem 'capybara'
gem 'pry-rails'
gem 'shoulda-matchers', github: 'thoughtbot/shoulda-matchers'
end
stylesheets/application.css:
/*
* 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 bootstrap_and_overrides
*= require_tree .
*= require_self
*/
stylesheets/bootstrap_and_overrides.css.less
#import "twitter/bootstrap/bootstrap";
// Set the correct sprite paths
#iconSpritePath: image-url("twitter/bootstrap/glyphicons-halflings.png");
#iconWhiteSpritePath: image-url("twitter/bootstrap/glyphicons-halflings-white.png");
// Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines)
#fontAwesomeEotPath: font-url("fontawesome-webfont.eot");
#fontAwesomeEotPath_iefix: font-url("fontawesome-webfont.eot?#iefix");
#fontAwesomeWoffPath: font-url("fontawesome-webfont.woff");
#fontAwesomeTtfPath: font-url("fontawesome-webfont.ttf");
#fontAwesomeSvgPath: font-url("fontawesome-webfont.svg#fontawesomeregular");
// Font Awesome
#import "fontawesome/font-awesome";
// Glyphicons
//#import "twitter/bootstrap/glyphicons.less";
// Your custom LESS stylesheets goes here
//
// Since bootstrap was imported above you have access to its mixins which
// you may use and inherit here
//
// If you'd like to override bootstrap's own variables, you can do so here as well
// See http://twitter.github.com/bootstrap/customize.html#variables for their names and documentation
//
// Example:
// #link-color: #ff0000;
javascripts/application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .
layouts/application.html.erb:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Odot2</title>
<!-- Latest compiled and minified CSS -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Odot2</a>
</div>
<div class="user-links collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<% if user_signed_in? %>
<li role='presentation'><%= link_to('Logout', destroy_user_session_path,
:method => :delete) %></li>
<li role='presentation'><%= link_to('Edit registration',
edit_user_registration_path) %></li>
<% else %>
<li role='presentation'><%= link_to('Login', new_user_session_path) %></li>
<li role='presentation'><%= link_to('Register', new_user_registration_path) %></li>
<% end %>
</ul>
</div>
</div>
</nav>
<div class="flash panel">
<% flash.each do |type, message| %>
<div class='<%= build_alert_classes(type) %>'>
<%= message %>
</div>
<% end %>
</div>
<main>
<div class="container-fluid">
<%= yield %>
</div>
</main>
</body>
</html>
I used the Bootstrap-sass gem and it works fine.
gem 'bootstrap-sass'
//= require bootstrap
and then in a file called "Bootstrap_and_customization.css.scss" I have:
#import url(http://fonts.googleapis.com/css?family=Lato:400,700);
#import 'bootstrap-sprockets';
#import 'bootstrap';
#import url("//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css");
I am trying to display a modal that includes an object's information. I am running Rails 4, and Bootstrap 3. I followed an example on SO and have received an error:
Sprockets::FileNotFound in Gifts#index
couldn't find file 'bootstrap-modal'
My Gemfile looks like this:
gem 'rails', '4.0.0'
gem 'bootstrap-sass', '3.0.2.0'
gem 'activeresource'
group :assets do
gem 'jquery-ui-rails'
gem 'jquery-modal-rails'
end
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
gem 'factory_girl_rails', '4.2.1'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'devise'
gem 'activeadmin', github: 'gregbell/active_admin'
gem 'paperclip'
gem 'aws-sdk'
gem 'rmagick', '2.13.2'
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
Application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-modal
//= require_tree .
$(document).ready(function() {
$('#modal-window').modal('show');
$('.modal-body').html('<%= escape_javascript(render :partial => "recipient_data", :object => #gift) %>');
});
Show.html.erb
<div class="modal hide fade" id="modal-window">
<div class="modal-header">
×
</div>
<div class="modal-body center">
<h2>Hello, World</h2>
<%= render 'charges/recipient_data' %>
</div>
<div class="modal-footer">
</div>
</div>
The link to the modal on my index page
<%= link_to 'Show', gift_path(gift), {:remote => true,
'data-controls-modal' => "modal-window",
'data-backdrop' => true,
'data-keyboard' => true,
:class => "btn btn-primary ", :id => 'show_gift'} %>
How should I load bootstrap-modal in this case?
The current version of bootstrap-sass uses a slightly different require line (with a / instead of a -)
//= require bootstrap/modal
However, since you're already including a //= require bootstrap, there is no need to require the modal file separately.