Bootstrap sass gem conflicts between versions 2&3 - ruby-on-rails

I'm using bootstrap-sass gem in my Rails project with version 2.3.1.0. However, when pushed up to Heroku, I'm getting the Bootstrap 3 styles. I inspect the CSS style and it indeed does say Bootstrap version 3.
On local, the assignment seems to be correct. But equally perplexing, when I inspect the CSS file, it says Bootstrap version 3 despite displaying what looks like the Bootstrap 2.3 styles.
I think at one point, my bootstrap-sass gem was using the Bootstrap 3, but when I put it back to gem 'bootstrap-sass', '2.3.1.0', I'm getting this strange conflict. I really just want my Heroku app to display the styles correctly. Even though I'm pushing up my current local version to Heroku, it is still using Bootstrap 3 stylings.
Here's what I've got:
Gemfile:
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass', '2.3.1.0'
end
I've created a styles.css.scss file, where I have the line #import "bootstrap";Here's what it looks like on localhost:
Here's what it looks like on Heroku:

It sounds like your Gemfile.lock might be incorrect. Have you verified that the correct version of the bootstrap gem is defined in Gemfile.lock?
Also might be worth just checking nothing is set in the Heroku env variable BUNDLE_WITHOUT. See the Heroku gem docs.

Not sure why this worked, but I found the second answer here to work for me.
I added *= require bootstrap" right above " *= require_tree . in application.css.
Then ran "bundle install --without production", followed by "rake assets:precompile". Committed the changes to git and then pushed to heroku.
I've never had to specifically require bootstrap in the asset pipeline before, but it works!

Related

zurb-foundation gem not added to asset path in existing Rails 3.2 application

I have an existing Rails 3.2.14 application that I am trying to add zurb-foundation to. I have added the zurb-foundation gem and run the installation generator.
My problem is that, whenever I try to load a page, I get this error:
couldn't find file 'foundation'
when Sprockets hits the
//= require foundation
line in application.js
The problem appears to be that the directory with the assets from the zurb-foundation gem are not being added to the load path. In contrast, I have an application that I generated more recently, including zurb-foundation from the beginning, and #asset_paths.asset_environment.paths includes the following
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-rails-3.0.4/vendor/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.0/scss",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.0/js"
which are not included in the asset load path in the app I am updating. Instead, I am getting (with p #asset_paths.asset_environment.paths in the better_errors diagnostic window)
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/images",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/stylesheets",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-rails-3.0.4/vendor/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/assets/javascripts"
interestingly, if I run the console in development mode and look at Rails.application.config.assets.path, it includes:
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/images",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-ui-rails-4.0.4/app/assets/stylesheets",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jquery-rails-3.0.4/vendor/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/assets/javascripts",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.1/scss",
"/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/zurb-foundation-4.3.1/js"
and that DOES include the zurb-foundation asset paths.
I have included gem 'zurb-foundation' in the assets group, in the development group, and outside any group. I am using zurb-foundation-4.3.1 in the new app.
My Gemfile assets group is:
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
gem 'compass-rails'
gem 'zurb-foundation'
end
This problem seems similar to Sprockets::FileNotFound with ZURB Foundation, although Jurriaan did not mention the asset load path.
Any idea what I could be missing?
Thanks!
Have you tried restarting the webserver?
Update:
You said it runs fine in development, Have you tried to rake assets:clean and rake assets:precompile?
It was a problem with a gem that was preventing foundation's entries being added to the load_path. The gem involved was mongomapper-versioned.
By not loading that gem, the problem resolved. By adding the gem back, the problem recurs.
That gem has not had any activity for two years. I guess it's time to find something else.

Gumby Framework in Rails Project - File to import not found

I have a simple rails project (ruby 1.9.3, rails 3.2.13), and I am attempting to incorporate the Gumby CSS Framework. The framework requires Compass, with modular-scale.
For sake of completeness the majority of the post contains information, skip to the end for the actual problem.
The working directory is being watched with
$ compass watch`
Compass was incorporated into the project with:
compass create --app rails \
-l ./app/assets/stylesheets/gumby/ \
--using modular-scale
The contents of config/compass.rb is:
require 'modular-scale'
project_type = :rails
And the location of Gumby source (SCSS) is app/assets/stylesheets/gumby.
The resulting compiled css appears in public/assets/gumby/gumby.css.
The following is within my Gemfile
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'compass-rails'
gem 'coffee-rails', '~> 3.2.1'
gem 'modular-scale'
gem 'gumby-rails'
gem 'uglifier', '>= 1.0.3'
end
And bundle install completes without errors.
However...
The following error message appears on all served pages:
Sass::SyntaxError in Users#index
Showing PROJECT_ROOT/app/views/layouts/application.html.erb where line #5 raised:
File to import not found or unreadable: compass/typography/vertical_rhythm.
Load path: Sass::Rails::Importer(PROJECT_ROOT/app/assets/stylesheets/gumby/_base.scss)
(in PROJECT_ROOTr/app/assets/stylesheets/gumby/_base.scss)
After hours of tinkering, I am at a loss as to the reason why Sass cannot read the Compass library.
I believe I found the solution from https://stackoverflow.com/a/9021785/1280997.
Removing config/compass.rb and rebooting the server fixes the immediate problem, however I am now faced with:
Undefined mixin 'box-sizing'.
(in PROJECT_ROOT/app/assets/stylesheets/gumby/_base.scss)
Ok, after much digging, I've found a way to incorporate Gumby into Rails, however I've lost the ability to edit the scss in the process. I did this using the gumby-framework gem. Setup was simple, following the README.

Rails 3.1 asset pipeline not working

I am in the process of upgrading an old app to the asset pipline but after following the ryan bates tutorial on upgrading to 3.1 I am still not able to take advantage of the pipline. In order to rule out my upgrade process I created a fresh rails app and attempted some coffee scripting and adding other files to the /assets/javascripts folder, however any additional files besides the application.js do not seem to be rendered.
This is my application.js file:
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
alert("this displays fine");
And the additional dogs.js.coffee file:
# 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://jashkenas.github.com/coffee-script/
alert "cant see this!"
It seems to be a sprockets issue but I really cant find anyone with the same problem, or info on when additional javascript files within the assets folder are not included in the application.js via the require_tree .
Here is my gem file:
gem 'rails', '3.1.1'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
my ruby version is 2.0.0p195
thanks for any help!
G
It seems the ruby version was my problem, I downgraded to ruby 1.9.3, then reinstalled gems and it works now!

Remove gem from default gemfile?

When using rails new, the following gems are automatically included in a Gemfile:
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
I'm not a huge fan of SASS, and I strongly dislike Coffeescript, and it's getting annoying having .scss and .js.coffee files in every new project.
How can I remove these gems from rails new so that they won't be included by default in every new project?
Thanks for any responses in advance.
To answer your question: You can always create your own template.rb and pass that into rails new using the --template or -m option. RailsWizard will even generate a template for you.
Let me also say that the default template doesn't generates any .scss or .coffee files, but it is a little annoying that the gems are bundled automatically. Mostly, though, you could ignore that they're installed--just remove those two lines from your Gemfile.

New Rails 3.1.3 + Datamapper routing assets issue

I am eager to try out DataMapper for a new Rails project. I created my project using the following command:
rails new project_name -m http://datamapper.org/templates/rails.rb
I decided to test out my application by running:
rails server
When I go to the generic home page that is created, I can't see any images. I get an error stating:
ActionController::RoutingError (No route matches [GET] "/assets/rails.png")
If I create any other scaffolds and visit those pages, I get similar errors about the stylesheets or javascript not found. I double checked to ensure that a regular Activerecord-rails application worked (which it did). I'm rather puzzled. Any help would be greatly appreciated. Thank you :)
For some reason, DataMapper's Rails template completely replaces the standard Gemfile with their own, which doesn't include any of the asset handling stuff (it also removes a handful of other things like jQuery support, TestUnit, ActionMailer...).
You'll want to add these back in to your Gemfile after setting up the new application:
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
Per Frederick's suggestion below, you'll also want to add this into your config/application.rb file:
require 'sprockets/railtie'
I opened an Issue and submitted a pull request to fix this.
Update: As of 1/5/2012, this is now fixed. The template behaves nearly identical to a standard Rails 3.1 app with the only change being ActiveRecord being replaced with DataMapper. Assets/jQuery support now works.

Resources