I am trying to setup bootstrap on Rails4 using bootstrap-sass and I am getting this famous error:
Sprockets::FileNotFound - couldn't find file 'bootstrap'
(in app/assets/javascripts/application.js:16):
I have tried following:
twitter/bootstrap in application.js
gem 'bootstrap-sass', '~> 3.1.0' is outside group assets
Also tried bunch of other things on internet
I have spend lot of time taking different suggestions from other posts. How do I systematically debug this , how to setup bootstrap-sass ?
p.s:
Also been trying to get twitter-bootstrap-rails working with no luck.
Here are some files
application.js
//= require jquery
//= require jquery_ujs
//= require js-routes
//= require bootstrap
//= require_tree .
//= require bootstrap-slider
application.css.scss
*= require jquery.ui.core
*= require jquery.ui.theme
*= require_self
*= require bootstrap-slider
*= require_tree .
*= stub active_admin
*/
#import "bootstrap";
Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.0'
gem 'sass-rails'
gem 'coffee-rails', git: 'git://github.com/rails/coffee-rails.git'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-ui-rails'
gem 'font-awesome-sass'
gem 'less-rails'
gem 'therubyracer', :platform=>:ruby
#gem 'twitter-bootstrap-rails'
gem 'jquery-rails'
#gem 'jquery_mobile_rails'
gem 'js-routes'
gem 'cancan'
gem 'devise'
gem 'figaro'
gem 'haml-rails'
gem 'pg'
gem 'rolify'
gem 'sendgrid'
gem 'simple_form'
gem 'thin'
gem 'rake'
#To use db for storing cookies instead cookie-store
gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
group :development do
gem 'better_errors'
#gem 'binding_of_caller', :platforms=>[:mri_19, :rbx]
#Commenting out platforms part, because may be that's stopping this to be used on the dev machine'
gem 'binding_of_caller'
gem 'guard-bundler'
gem 'guard-rails'
gem 'guard-rspec'
gem 'html2haml'
gem 'quiet_assets'
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', :require=>false
# Required with Rails panel chrome extension. This Gem should come after better_errors gem
gem 'meta_request'
end
group :development, :test do
gem 'factory_girl_rails'
gem 'rspec-rails'
gem 'pry-byebug'
gem 'pry-stack_explorer'
gem 'pry-rails'
gem 'pry-debugger'
end
group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'email_spec'
end
group :production do
gem 'rails_12factor'
end
gem 'high_voltage'
#Linkedin Logins
gem "linkedin"
gem "omniauth"
gem "omniauth-linkedin"
gem "omniauth-facebook"
#postgres use hstore in active record
#gem 'activerecord-postgres-hstore'
gem 'state_machine'
gem "ruby-graphviz"
#payments
#gem 'stripe',:git => 'https://github.com/stripe/stripe-ruby'
#gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails', :github => 'anjlab/bootstrap-rails'
gem 'newrelic_rpm'
gem 'pgbackups-archive'
gem 'pg_search'
gem 'acts-as-taggable-on'
#gem 'activeadmin' , github: 'gregbell/active_admin'
gem "activeadmin", git: "https://github.com/gregbell/active_admin"
gem 'kaminari'
gem 'bootstrap-slider-rails'
gem 'bootstrap-sass', '~> 3.1.0'
Installing the Bootstrap Gem
1.) Add the Bootstrap Gem:
gem 'bootstrap-sass'
2.) Understand The Application.css File
app/assets/stylesheets/application.css
Application.css takes all the other files in your /stylesheets directory and combines them for when you run your app.
3.) Create a New SCSS File (app/assets/stylesheets/bootstrap_and_customization.css.scss)
#import 'bootstrap';
4.) Require Bootstrap's JavaScript
...
//= require jquery
//= require jquery_ujs
//= require bootstrap <--
//= require turbolinks
//= require_tree .
5.) Rails Assets
group :production do
gem 'rails_12factor'
end
6.) Bundle Install & Restart Server
Thats should be it !
On one of my projects (Rails 4.1) I had to include the bootstrap directly (not sass). Maybe it will give a hint on making the saas version work. So below are steps to include the bootstrap directly:
Download and and extract the bootstrap to
Rails.root/vendor/assets/bootstrap
Create file Rails.root/vendor/assets/javascripts/bootstrap.js file with contents like this:
//= require ../bootstrap/js/bootstrap.js
Now the most important part to make icons work. The font file urls have to be overridden for the Glyphicons Halflings font. Also asset_path helper has to be used. So create file Rails.root/vendor/assets/stylesheets/bootstrap.css.erb file with contents like this.
/*
=require ../bootstrap/css/bootstrap.css
*/
#font-face {
font-family: 'Glyphicons Halflings';
src: url("<%= asset_path 'glyphicons-halflings-regular.eot' %>");
src: url("<%= asset_path 'glyphicons-halflings-regular.eot?#iefix' %>") format('embedded-opentype'), url("<%= asset_path 'glyphicons-halflings-regular.woff2' %>") format('woff2'), url("<%= asset_url 'glyphicons-halflings-regular.woff' %>") format('woff'), url("<%= asset_path 'glyphicons-halflings-regular.ttf' %>") format('truetype'), url("<%= asset_path 'glyphicons-halflings-regular.svg#glyphicons_halflingsregular' %>") format('svg');
}
Now require bootstrap in the application.js and application.css
application.js
//= require bootstrap
application.css
*= require bootstrap
And finally let assets pipeline be aware of the fonts path and additional extensions to precompile. In the application.rb add:
config.assets.paths << Rails.root.join("vendor", "assets", "bootstrap", "fonts")
config.assets.precompile += %w( *.eot *.svg *.ttf *.woff *.woff2 )
After that RAILS_ENV=production rake assets:precompile should show that is has recognized font files and copied them to the public assets folder.
Then to test if it works in production enable serving static assets (in production.rb: config.serve_static_assets = true) and RAILS_ENV=production rails s
I ended up using bootstrap from a hosted CDN
%link{href: "//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css", rel: "stylesheet"}/
%link{href: "//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" , rel: "stylesheet"}/
%link{href: "//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css", rel: "stylesheet"}/
I had exactly the same error. The solution was to change in:
config/environments/production.rb
The line
config.serve_static_assets = false
to
config.serve_static_assets = true
I'm not exactly aware of what this line does, but my workteam had the same problem on a project, and they changed this line, and it worked.
Try this:
Open config/application.rb, add the following line:
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
In your config.ru file, add
require 'bootstrap-sass'
Rename your application.css.scss to something else e.g. custom_bootstrap.css.scss. I have no idea why it makes a difference but it did in my case.
Also, from what I understand, by default bootstrap-sass does not require you to add
//require bootstrap
to your application.js. Apparently it breaks some kind of functionality.
i had the same issue :couldn't find file 'bootstrap-sprockets' with type 'application/javascript'
The only solution was to comment off in the Gemfile
gem 'sass-rails', '~> 5.0' and add instead
gem 'sass-rails', '>= 3.2'
hope this helps other members
The fix for me was two parts ... my correct list first ... but the list alone wasn't the fix!
gem 'sass-rails', '~> 5.0'
gem 'bootstrap-sass', '~> 3.3.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
Then I had a gemfile.Lock issue ... if anyone else can't get the files to load & doesn't want to use the CDN...check your gemfile.Lock & see what versions are compiled off the gemfile (one is input for us as dev's & the other is what is actually ran by the framework - it will cause issues if you try to modify gemfile.lock).
To resolve the gemfile lock...close the gemfile & gemfile.Lock
I had to first delete the items in question from the "gemfile".
I did a "gem install <name of gemfile>" I wanted for each of them.
Then open the gemfile & gemfile.Lock to check results. Note, you still have to do all the configuration bootstrap etc requires for each of these. It doesn't hurt to run a rails assets:precompile either.
Note: The rails assets:precompile is a rails 5 command.
add to Gemfile
gem 'font-awesome-rails'
do bundle install
add to application.css
*= require font-awesome
and, restart rails server.
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 .
I felt strange that why the style not loaded,
So I wrote wrong content intentionally on application.css.scss,
And precompile and load the page didn't give me any error.
I thought the application.css.scss file must not be loaded and compiled.
Unfortunately, it seems no to be.
application.css.scss
#i2dmport "compass";
/*
* 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 vendor/assets/stylesheets of plugins, if any, 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 top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require jquery.fileupload-ui
*= require dropzone/dropzone
*= require dropzone/basicdew
*= require_tree .
*/
#import "layout";
application.rb
config.autoload_paths += %W(#{Rails.root}/app/pdfs)
config.autoload_paths += %W(#{config.root}/lib/)
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
config.assets.paths << "#{Rails.root}/vendor/themes"
Gemfile (I not sure if there any conflict)
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.5'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.17.1'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
# 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', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem "bootstrap-sass", "~> 3.1.1"
gem "compass-rails"
gem "therubyracer"
gem "execjs"
gem "hirb-unicode"
gem "devise", "~> 3.3.0"
gem "devise_ldap_authenticatable", "~> 0.6.1"
gem "net-ldap"
gem "will_paginate", "~> 3.0"
gem "rspec"
gem "awesome_print", require: "ap"
gem "tinymce-rails"
gem "simple_form"
gem "haml-rails"
gem "taps"
gem "analytics-ruby"
gem "bcrypt-ruby"
gem "bourbon"
gem 'cancancan', '~> 1.8'
gem "sunspot_rails"
gem "sunspot_solr"
gem "simple-navigation"
gem "simple-navigation-bootstrap"
#fast command
gem "spring", group: :development
#Handy tools for active record
gem "squeel", "~> 1.2.1" # Last officially released gem
# gem "squeel", :git => "git://github.com/activerecord-hackery/squeel.git" # Track git repo
gem 'prawn'
gem 'rb-readline', "~> 0.5.0.pre.1"
gem 'chartkick'
gem 'rails-erd', :group => :development
gem 'quiet_assets', group: :development
gem 'curb'
gem 'rest_client'
# only for assets not required in production mode
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'jquery.fileupload-rails', "~> 1.10.0"
gem 'twitter-bootstrap-rails'
group :development do
gem "faker"
gem "rspec-rails"
gem "guard-rspec"
gem "pry"
gem "pry-remote"
gem "pry-nav"
gem 'pry-rescue'
gem 'pry-stack_explorer'
end
gem "paperclip", "~> 4.1"
gem 'dropzonejs-rails'
layout
!!!
%html
%head
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= stylesheet_link_tag params[:controller]
= javascript_include_tag "application", "data-turbolinks-track" => true
= javascript_include_tag params[:controller], "data-turbolinks-track" => true
i had this exact same problem and was driving me crazy. i had a app/assets/stylesheets/mycustom_stylesheet.css.scss with the styles that loaded fine in development but when i deployed to production on heroku, none of my styles appeared. i solved it by placing the file custom.css in my vendor/assets/stylesheets directory with this content:
/*
*= require mycustom_stylesheet
*/
i also added this line to my initializers/assets.rb file although i'm not sure its necessary.
Rails.application.config.assets.precompile += %w( mycustom_stylesheet.css )
May be you have an "application.css" file inside of your "/vendor/themes/" or "/lib" folder ?
What happens if you remove this line "config.assets.paths << "#{Rails.root}/vendor/themes" from your application.rb file?
Try running below command
RAILS_ENV=production rake assets:precompile
or
RAILS_ENV=development rake assets:precompile
Today I came across a similar problem that changes in application.css.scss does not update in page styling. Later I found out that is because there is an error in my .scss file, ul being misspelled as u1. After the error is fixed, the styling finally updates in page refreshes, with no need to restart rails server.
I am trying to show a paginated list of results back from a database and have ended up looking at using dataTables. I have been following rails cast 340 but hit a problem with the above error. I am running rails 3.1.12.
My files are as follows:
Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.1.12'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'therubyracer'
gem "less-rails"
gem 'uglifier', '>= 1.0.3'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-ui-rails'
end
gem 'jquery-rails'
gem 'savon', '2.5.1'
gem 'twitter-bootstrap-rails'
gem 'will_paginate'
application.js:
//= require jquery
//= require jquery.ui.all
//= require dataTables/src/demo_table_jui
//= require_tree .
application.cs
*= require_self
*= require dataTables/jquery.dataTables
*= require_tree .
nettica.coffee.js
jQuery ->
$('#domains').dataTable
sPaginationType: "full_numbers"
Any ideas?
Further on down the line I also get problems with adding:
bJQueryUI: true
to the above file.
Thank you
I am trying to deploy an app in rails 3.2.16, with capistrano on a vps. This is my first time doing that. During the deployment process, I get the following error: "couldn't find file "chosen-jquery" '. The rpoblem is that my gem versions and generally the whole environment is the same on the server and my testing machine. I get the error during the "assets:precompile" command execution.
Any suggestions?
I am using the gem chosen -v 1.0.2, rails 3.2.16 and Ruby 1.9.3.
Here is my gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.16'
gem 'mysql2'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'ckeditor', '4.0.4'
gem 'carrierwave', '0.8.0'
gem 'devise', '2.2.3'
gem 'globalize3', '0.3.0'
gem 'babosa', '0.3.9'
gem 'haml', '4.0.4'
gem 'friendly_id', '4.0.9'
gem 'simple_form', '2.0.4'
gem 'kaminari', '0.14.0'
gem 'nokogiri', '1.6.1'
gem 'jquery-fileupload-rails', '0.4.0'
gem 'ancestry', '1.3.0'
gem 'ransack', '0.7.2'
gem 'simple-navigation', '3.10.0'
gem 'mime-types', '~>1.21'
gem 'mini_magick', '3.5.0'
gem 'acts_as_list', '0.1.9'
gem 'chosen-rails'
gem 'pry'
gem 'passenger'
and my application.js manifest:
//= require jquery-1.10.2.min
//= require jquery_ujs
//= require ckeditor/init
//= require jquery.fancybox-1.3.4.pack
//= require jquery.easing-1.3.pack
//= require jquery.mousewheel-3.0.4.pack
//= require chosen-jquery
//= require scripts
//= require admin_scripts
Thank you in advance for your time and effort :)
You can try require the library manually (as file)
Just restart rails server. I had the same problem on Rails 4.1.5. I restarted rails server and it worked. See this Github issue
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).