I am struggling to adapt bootstrap 4 working in my Rails application. I have followed the instructions from here and here. I have placed simple navbar
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
</nav>
in my application.html.erb file but nothing changed. After a few hours of searching I found same questions here but no any working solution.
This is my Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.3.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# 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 'mini_racer', platforms: :ruby
# 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'
# 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
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'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data
gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'pry-rails', group: [:development, :test]
gem 'jquery-rails'
gem 'dotenv-rails', group: [:development, :test]
gem 'rspec-rails', group: [:development, :test]
gem 'capybara', group: [:development, :test]
gem 'launchy', group: [:development, :test]
gem 'factory_bot', group: [:development, :test]
gem 'database_cleaner', group: [:development, :test]
gem 'valid_attribute', group: [:development, :test]
gem 'shoulda-matchers', group: [:development, :test], require: false
gem 'devise'
gem 'bootstrap', '~> 4.1.3'
gem 'webpacker', '~> 3.3'
This is my app/stylesheets/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, 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 other CSS/SCSS
* files in this directory. Styles in this file should be added after
the
* It is generally better to create a new file per style scope.
*
#import 'bootstrap';
*/
here is my app/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, 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 jquery3
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-sprockets
//= require popper
//= require activestorage
//= require_tree .
Please help if you know how to set it up right. Thank you in advance.
#import 'bootstrap'; should be outside of your comments
/*
* 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, 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 other CSS/SCSS
* files in this directory. Styles in this file should be added after
the
* It is generally better to create a new file per style scope.
*
*/
#import 'bootstrap';
Related
First, I removed gem 'turbolinks' and removed the code requiring Turbolinks in the application.js file. So, I successfully disabled Turbolinks in my local machine. Then, I pushed my changes to Heroku, but Turbolinks is still working in production.
How can I disable Turbolinks in Heroku?
When I ran this code:
heroku run cat app/assets/javascripts/application.js
I got following code:
//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 jquery-ui/effects/effect-highlight
//= require bootstrap
//= require material
//= require materialize-sprockets
//= require custom
//= require cocoon
//= require underscore
//= require_tree .
Also, my Gemfile looks like this on the production environment:
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bcrypt', '3.1.7'
gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.36.0'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '2.5.3'
gem 'materialize-sass'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
gem 'omniauth-facebook'
gem 'figaro'
gem 'material_design_lite-sass'
gem 'material_icons'
gem "font-awesome-rails"
gem 'cocoon'
gem 'simple_form'
gem 'jquery-ui-rails'
gem 'activerecord-reset-pk-sequence'
gem 'underscore-rails'
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
gem "better_errors"
gem "binding_of_caller"
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '3.1.0'
end
I have also removed all Turbolinks references in application.html.erb.
But still, Turbolinks isn't being disabled in production environment. What can be the fix?
Note: Turbolinks is successfully disabled in my development environment.
Make "data-turbolinks-track" => false in file app/views/layouts/application.html.erb
Basically straight from here. It's for Rails 4, but I believe the steps are the same.
1) Remove the gem 'turbolinks' line from your Gemfile.
2) Remove the //= require turbolinks from your app/assets/javascripts/application.js .
3) Remove the two "data-turbolinks-track" => true hash key/value pairs from your app/views/layouts/application.html.erb .
Hey when i type "rake assets:precompile" on terminal it shows error like this
I, [2016-05-05T13:52:42.537665 #11661] INFO -- : Writing /Users/paras/Hackathon_hackerearth/hackathon_1/public/assets/application-e73a0a56296d201e9779eb9ca13396a60e55ba64dee295f7fb3f1f39a64fee90.js
I, [2016-05-05T13:52:42.545034 #11661] INFO -- : Writing /Users/paras/Hackathon_hackerearth/hackathon_1/public/assets/application-e73a0a56296d201e9779eb9ca13396a60e55ba64dee295f7fb3f1f39a64fee90.js.gz
rake aborted!
Sprockets::FileNotFound: couldn't find file 'foundation_and_overrides' with type 'text/css'
/Users/paras/Hackathon_hackerearth/hackathon_1/app/assets/stylesheets/application.css:17
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
zlib(finalizer): Zlib::GzipWriter object must be closed explicitly.
zlib(finalizer): the stream was freed prematurely.`
My Gem file is here
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
gem 'pry'
#for password
gem 'bcrypt'
#for creating fake users
gem 'faker'
#for tagging
gem 'foundation-rails'
#for rating
gem 'ratyrate'
#for pagination
gem 'will_paginate'
gem 'bootstrap-will_paginate'
#bootstrap
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
# 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
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# 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'
end
group :development do
# 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'
end
gem 'rails_12factor', group: :production
ruby "2.3.0"
gem 'puma'
here is my application.js file's data
//= require jquery
//= require jquery_ujs
//= require foundation
//= require bootstrap
//= require_tree .
$(function(){ $(document).foundation(); });
and here is my application.css file
/*
* 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
*= require foundation_and_overrides
*/
please tell me that what is wrong with it. i searched it but no hint could solve this error. i am working on OS X El Capitan.
Do you have a CSS file whose name starts with foundation_and_overrides in your assets/stylesheets folder?
It can't find it.
I've been playing with react-rails gem and so I made a sample application with haml. When I do rails s and go to my sample route, I see the attached error coming from application.html.haml, the standard layout/application.html.haml view in Rails 4.2. If I remove stylesheet_link_tag and javascript_include_tag the Rails view renders fine. What could be causing it? Below are the relevant files. There is also a sample.coffee file but I can't imagine that has anything to do with it since as soon as I remove the *_tag helpers the Rails view renders without error.
application.js.coffee
# 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 react
#= require react_ujs
#= require components
#= require_tree .
application.html.haml
!!!
%html
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title SampleApp
= stylesheet_link_tag 'application', media: 'all'
= javascript_include_tag 'application'
= csrf_meta_tags
%body
= yield
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_tree .
*= require_self
*/
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# 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
# 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
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'react-rails', '~> 1.6.0'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# 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'
end
gem 'httparty'
gem 'haml-rails'
gem 'annotate'
gem 'figaro'
gem 'pundit'
gem 'lol_dba', require: false
gem 'foreman'
gem 'newrelic_rpm'
group :development do
gem 'sextant'
gem 'awesome_print', require: false
gem 'hirb', require: false
gem 'bullet'
gem 'flog', require: false
gem 'flay', require: false
gem 'reek', require: false
gem 'derailed'
gem 'stackprof'
gem 'sandi_meter'
gem 'rubocop', require: false
end
group :development, :test do
gem 'spring-commands-rspec'
gem 'rspec-rails'
gem 'guard-rspec'
gem 'pry'
end
group :test do
gem 'factory_girl_rails'
gem 'capybara'
gem 'database_cleaner'
gem 'launchy'
gem 'codeclimate-test-reporter', require: nil
gem 'shoulda-matchers', require: false
end
group :production, :staging do
gem 'rails_12factor'
gem 'puma'
end
Good day,
I made an app with masonry and js.coffee to make something like "pins" in my app, but when I deploy to Heroku don't work like suppose to do.
This is my gem file
source 'https://rubygems.org'
ruby '2.1.4'
gem 'binding_of_caller'
gem 'masonry-rails', '~> 0.2.0'
gem 'haml'
gem 'high_voltage', '~> 2.3.0'
gem 'activevalidators'
gem 'paperclip', github: 'thoughtbot/paperclip'
gem 'simple_form', '~>3.0.2'
gem 'acts_as_votable'
gem 'bootstrap-sass'
gem 'devise', '~> 3.4.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
# 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
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :assets do
gem 'therubyracer'
gem 'less-rails'
gem 'twitter-bootstrap-rails'
gem 'libv8'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'sqlite3'
# 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'
end
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.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-sprockets
//= require masonry/jquery.masonry
//= require turbolinks
//= require_tree .
My js.coffee to show pins
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$ ->
$('#pins').imagesLoaded ->
$('#pins').masonry
itemSelector: '.box'
isFitWidth: true
My index for pins
- content_for :board do
= javascript_include_tag 'application', 'data-turbolinks-track' => true
#pins.transitions-enabled
- #pins.each do |pin|
.box.panel.panel-default
= link_to (image_tag pin.image.url), pin
%h2
= link_to pin.title, pin
%p.user
Ofertado por
= pin.user.name
%p.price
$
= pin.price
Am I doing something wrong?
If it works well under development and won't work upon deployment in heroku, you might have mistakenly configured your database.yml under config.
production:
adapter: postgresql
encoding: utf8
database: (copy database name from your heroku database info)
username: (copy username from your heroku database info)
password: TV9ncj-HR1FqNFihKm6zlsHhxU
host: (copy host from your heroku database info)
sslmode: require
and don't forget to do the rake db:migrate
if this is not the answer you were looking for, this might still be a little useful for you, if not now, maybe in the near future as you go along with your code.
I am following Michael Hartl's Rails guide, and when I load localhost:3000 I get the following error messages in the browser:
Sprockets::FileNotFound in Static_pages#home
Showing /home/jonathan/Desktop/railsTut/sample_app/app/views/layouts/application.html.erb where line #6 raised:
couldn't find file 'turbolinks'
(in /home/jonathan/Desktop/railsTut/sample_app/app/assets/javascripts/application.js:16)
This is my file from the aformentioned message
// 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 vendor/assets/javascripts of plugins, if any, 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
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree .
also, I am not sure if it is related, but here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'jquery-rails', '2.0.2'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
# gem 'guard-rspec', '1.2.1'
# gem 'guard-spork', '1.2.0'
# gem 'childprocess', '0.3.6'
# gem 'spork', '0.9.2'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
group :development do
gem 'annotate', '2.5.0'
end
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '4.2.1'
gem 'cucumber-rails', '1.2.1', :require => false
gem 'database_cleaner', '0.7.0'
# gem 'launchy', '2.1.0'
# gem 'rb-fsevent', '0.9.1', :require => false
# gem 'growl', '1.0.3'
end
group :production do
gem 'pg', '0.12.2'
end
Any help is much appreciated!
As I see, you dont have 'turbolinks' in your gemfile... just add it! :
Add gem 'turbolinks' to your Gemfile.
Run bundle install.
Add //= require turbolinks to your Javascript manifest file (usually
found at app/assets/javascripts/application.js).
Restart your
server, and you're now using turbolinks!
As RomanDev said just remove it, unless like me you were trying to get ride of turbolinks.
In which case remove //= require turbolinks from your application.js file.
It took me way too long to realize that adding turbolinks to the gemfile would fix this. I'm also going through Hartl's tutorial as a beginner (obviously).