rails 4.2.0, sass-rails 5.0.1, and bootstrap-sass 3.3.3 Undefined variable: "$state‐danger‐text" - bootstrap-sass

I'm trying to follow Michael Hartl's Ruby on Rails Tutorial 3rd Edition with a slightly modified Gemfile and Sassy CSS files. When I try to use bootstrap-sass variables and mixins to display bootstrap powered validation errors in my custom.css.scss I get "Undefined" error.
I've confirmed that the variable exists in my {"bundle show bootstrap-sass" path}/assets/stylesheets/bootstrap/_variables.scss It seems like it doesn't lookup that file before throwing the error.
Please let me know how to fix this issue. Thanks a lot!
Here is my Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use pg as the database for Active Record
gem 'pg', '0.18.1'
gem 'bcrypt', '3.1.7'
gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.23.0'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass', '3.3.3'
# Use SCSS for stylesheets
gem 'sass-rails', '5.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '2.7.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '4.0.3'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '2.5.3'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '2.2.6'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '0.4.1', 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', '3.5.1'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '2.0.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', '1.2.0'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'rails_12factor', '0.0.3'
gem 'puma', '2.11.1'
end
Here is my application.css.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, 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_self
*/
#import "bootstrap-sprockets";
#import "bootstrap";
#import "custom.css.scss"
And Here is my custom.css.scss
#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}
.field_with_errors {
#extend .has‐error;
.form‐control {
color: $state‐danger‐text;
}
}

After 20 hours, I finally found out that I get the error only when I copy the codes from the tutorial to sublime text 2. I wrote every related line myself and it is now working as it should, no errors. May be some weird character is sneaking in when I copy. Quite strange!

Related

Why am I getting this error in my rails solidus app after installing bootstrap?

I am trying to set up a solidus app with custom css using bootstrap-sass. (I am following this tutorial)
Prior to getting this error, the page would load just fine but none of the bootstrap css would load correctly. This error started after I added
#= require bootstrap_sprockets
#= require_tree
to my all.coffee file
and adding
gem 'sassc-rails'
to my Gemfile
the complete all.sass file:
#import "bootstrap-sprockets"
#import "bootstrap"
the complete all.coffee file:
#= require jquery
#= require jquery_ujs
#= require spree
#= require bootstrap_sprockets
#= require_tree
the complete Gemfile:
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'
# 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
gem 'bootstrap-sass'
gem 'sassc-rails'
gem 'solidus'
gem 'solidus_auth_devise'
gem 'deface'
# 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]
when I run the server I get the following error:
Error: Function very-light finished without #return
on line 38:34 of ../../.rvm/gems/ruby-2.6.3/gems/solidus_backend-2.2.2/app/assets/stylesheets/spree/backend/globals/_variables.scss, in function `very-light`
from line 38:34 of ../../.rvm/gems/ruby-2.6.3/gems/solidus_backend-2.2.2/app/assets/stylesheets/spree/backend/globals/_variables.scss
from line 6:9 of ../../.rvm/gems/ruby-2.6.3/gems/solidus_backend-2.2.2/app/assets/stylesheets/spree/backend/spree_admin.scss
>> $color-border: very-light($color-3, 12) !default;
I'm not sure what exactly I need to do to fix this. I've made sure that I have the required gems for bootstrap-sass in my Gemfile and I've tried running bundle update.
the latest sassc-rails gem implemented via sassc, wich requires all CSS functions should ensure that they do not end without a #return statement.
and solidus fix it after v2.9, you can see it on https://github.com/solidusio/solidus/commit/aeba736e742eaf39e45b294433e33d663ac66f24

Heroku Error Compiling CSS Asset

In my latest deploy to Heroku I'm getting this error:
Error compiling css asset
Rack:Timeout:RequestTimeoutException: Request waited 3ms, then ran for longer than 1500ms
/app/vendors/bundle/ruby/2.20/gems-sass-3.4.22/lib/sass/tree/visitors/to_css.rba;67:in 'erase!"
I'm not quite sure what has caused the issue, but I've narrowed it down to a specific deploy where things were working before but were broken after. The only thing I changed were html files and changed the value of a sass variable in one of the stylesheets. I committed to git then deployed to Heroku. I realized then that my jQuery wasn't working on the page, so I then precompiled locally (as I usually do) and deployed . Now the application is throwing that error and exceeding it's available memory. Yet, everything works just fine in development. Anyone have any idea of what went wrong?
EDIT: I should add that the Rack timeout error is thrown by the rack-timeout gem which is designed to stop slow requests and log an error. So this isn't directly the issue, rather a result of an underlying problem that's prevented the page from responding within the allocated amount of time.
Here's the gemfile as requested:
#Use Jasny Bootstrap extension for input mask
gem 'jasny-bootstrap-rails'
#Use for Blog tags
gem 'acts-as-taggable-on', '~> 3.4'
#Use Carrierwave for image upload, fog for AWS S3
gem 'carrierwave'
gem "fog-aws"
gem "mini_magick"
# Use bootstrap will-paginate for pagination styling
gem 'will_paginate-bootstrap'
#Use will paginate for pagination
gem 'will_paginate', '~> 3.1'
#Use BetterLorem for seed text
gem 'betterlorem', '~> 0.1.2'
# Use date_validator gem to validate Event start & end times
gem 'date_validator', '~> 0.9.0'
# Use Bcrpyt for password encryption
gem 'bcrypt', '~> 3.1', '>= 3.1.11'
#Use FontAwesome for icons
gem "font-awesome-rails"
# Use to obfuscate email addresses on site
gem 'actionview-encoded_mail_to', '~> 1.0', '>= 1.0.7'
# Use to show instagram feed
gem 'instagram', '~> 1.1', '>= 1.1.6'
#Use TinyMCE to edit html content in posts
gem 'tinymce-rails'
# Use Jquery-turbolinks to fix turbolink issue
gem 'jquery-turbolinks'
# Timesout request that take longer than 15 seconds
gem "rack-timeout"
#Breadcrumb navigation
gem "breadcrumbs_on_rails"
# Use Gibbon for Mailchimp API navigation
gem 'gibbon', '~> 2.2', '>= 2.2.4'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'pry', '~> 0.10.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.3', '>= 1.3.11'
# Use for storing environmental variables
gem 'dotenv-rails'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Tracks memory usage of each gem
gem 'derailed'
# 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
gem 'minitest', '~> 5.8', '>= 5.8.4'
gem 'mini_backtrace', '~> 0.1.3'
gem 'guard-minitest', '~> 2.4', '>= 2.4.4'
gem 'guard'
gem 'minitest-reporters', '~> 1.1', '>= 1.1.8'
end
group :production do
gem 'pg', '~> 0.18.4'
gem 'rails_12factor', '~> 0.0.3'
gem 'puma'
end

Bootstrap is not styling anything with Ruby on Rails

I am using Bootstrap for the first time and it is not styling anything. I have already applied the answers from Bootstrap is not styling anything
and still no luck.
I have #import "bootstrap"; in my stylesheet
I also have the appropriate gems in my Gemfile. Here it is:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.5'
# Use sqlite3 as the database for Active Record
group :development,:test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
gem 'autoprefixer-rails'
group :assets do
gem 'sass-rails', '~> 4.0.3'
# 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'
gem 'bootstrap-sass', '~> 3.2.0'
end
# See https://github.com/sstephenson/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
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# 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
# Use debugger
# gem 'debugger', group: [:development, :test]
1) Add
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
to application.rb (inside the class)
2) Add #import 'bootstrap'; to the top line of a new CSS file.
Rails 4 does not use an assets group in Gemfile, So remove that & then edit your application.css to include following:
#import "bootstrap-sprockets";
#import "bootstrap";
Note: "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
Now add require Bootstrap Javascripts in app/assets/javascripts/application.js:
//= require jquery
//= require bootstrap-sprockets

Rails 4 - Heroku deploy works but images in CSS file do not appear

I have tried multiple ways to get some images to show up that are embedded in my style.css.erb file upon a Heroku deploy. I have no problems with the images showing up locally just upon deploy so I am assuming this is due to the precompiled assets. Here is what I have, any help/advice is much appreciated:
style.css.erb
#parallax1{
background-image:url('<%= asset_path("parallax/1.jpg")%>');
}
#parallax2{
background-image:url('<%= asset_path("parallax/2.jpg")%>');
}
#intro{
position: relative;
margin: 0 auto;
width: 100%;
overflow-x: hidden;
height:650px;
z-index:2;
background-image: url('<%= asset_path("bgslides/3.jpg")%>');
background-size:cover;
}
production.rb
config.assets.precompile += %w( jquery.js bootstrap.min.js jquery.nav.js jquery.scrollTo.js grid.js custom.js stellar.js modernizr.custom.js jquery.simple-text-rotator.min.js wow.min.js mb.bgndGallery.effects.js mb.bgndGallery.js font-awesome.css.scss.erb animate.css bootstrap.min.css simpletextrotator.css style.css.erb *.jpg *.png )
assets.rb
config.assets.precompile += %w( jquery.js bootstrap.min.js jquery.nav.js jquery.scrollTo.js grid.js custom.js stellar.js modernizr.custom.js jquery.simple-text-rotator.min.js wow.min.js mb.bgndGallery.effects.js mb.bgndGallery.js font-awesome.css.scss.erb animate.css bootstrap.min.css simpletextrotator.css style.css.erb *.jpg *.png )
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module DryerPlug
class Application < Rails::Application
config.assets.paths << Rails.root.join("app", "assets", "fonts")
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# 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)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# 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
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:
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 'spring', group: :development
gem 'mail_form'
gem 'simple_form'
gem 'pg', group: :production
gem 'rails_12factor', group: :production
SCSS
The problem you have is you're calling a ruby-on-rails erb methods in your CSS - which, although feasible, will likely cause a multitude of problems down the line
A much better way to resolve this is to use one of the Rails CSS preprocessors so your application can precompile the assets properly. The typical CSS preprocessor is SCSS:
#app/assets/stylesheets/application.css.scss
#parallax1{
background-image: asset_url("parallax/1.jpg");
}
--
Precompile
You need to keep your stylesheets 100% CSS (or SCSS) - as when you precompile them (required for deploying to Heroku), Rails won't be able to use much of the logic / functionality an erb file would create
Although you are correct when you've used the erb functionality, the best way is to use the SCSS preprocessor. On top of this, you need to ensure you've precompiled your assets locally:
$ rake assets:precompile RAILS_ENV=production
$ git add .
$ git commit -a -m "Precompiled"
$ git push heroku master
Did you try compiling the assets locally? That is what usually what works for me.
First clean the current assets
rake assets:clean
Then precompile them again
rake assets:precompile
Then commit these assets and push to Heroku. If this doesn't work, try to run in in production mode by adding RAILS_ENV=production to each command.

Exact same one-line SASS code works in one rails project, but not another

First of all this is my first time posting a question on StackOverflow. I'm a big fan. Anyway:
I was doing the Rails Tutorial by Michael Hartl when, after editing the custom.scss.css file, I suddenly got this error:
SASS Syntax error
Undefined variable: "$gray".
(in /home/shady/workspace/ruby/sample_app/app/assets/stylesheets/custom.css.scss:4)
This isn't a problem with $gray; it is the correct way to spell and capitalize the gray SASS variable (I checked, and it works in another rails project). I simplified the custom.scss.css file to pinpoint this error, so all it contains is this:
#import "bootstrap";
h1 {
color: $gray;
}
In my Sample App (the rails tutorial app), I still get this error, but when I use this exact same code in another rails project that I created (to practice the things I learned in the Rails Tutorial on my own, so it pretty much mimics the Sample App), with the exact same gemset and Gemfile, this works perfectly fine. Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=SecondTry
gem 'rails', '4.0.2'
gem 'bcrypt-ruby', '~> 3.1.2'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
gem 'guard-rspec', '2.5.0'
gem 'spork-rails', '4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
gem 'libnotify', '0.8.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.0'
gem 'jquery-rails', '>=3.0.4'
gem 'turbolinks', '2.2.0'
gem 'jbuilder', '1.0.2'
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
This was working perfectly fine the last time I edited custom.scss.css, and I haven't done anything substantial since then. I haven't (at least purposefully) edited any file that I think would cause this. I've tried uninstalling and reinstalling bootstrap-sass, but it hasn't worked. I believe it's a problem with SASS, but as I'm a rails newbie I have no clue on how to fix it. Any advice?
FIXED IT HAHAHAHAAAAAAA
It was because, for some stupid reason, I added an assets folder in the /vendor directory (probably testing something else out), and it seems that rails checks this directory for any external stylesheets and if it finds that it exists it loads from there instead of the gem (?), which is why bootstrap wasn't even processed by the Rails asset pipeline. The assets folder was empty save for a stylesheets and js folder. Once I deleted the assets folder the application started working again.
You need to defined your $grey var somewhere. In my rails projects i usually set a _colors.scss partial where i defined all my var and then i import them before bootsrap so i can override them if i need.
$grey:#EEEEEE;
I don't see any $grey var in the bootstrap var list (http://getbootstrap.com/customize/#less-variables).
Another idea, i don't know how you call your stylesheet in your layout. But maybe if you call application.scss only, there might be a missing *= require where your $grey is defined.

Resources