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.
Related
I am building a Rails application and I am in front of a weird issue in production: when capistrano compile assets Rails want to create a css version of all partials I included in application.sass and it breaks the deploy because of the variables and mixins I used in this partials.
In my application.sass:
#import compass
#import header // _header.sass file
#import footer // _footer.sass file
#import content // _content.sass file
...
I don't understand why because in another project I don't have this problem.
Here is my assets.rb file:
Rails.application.config.assets.version = '1.2'
Rails.application.config.assets.precompile += %w( email.css newsletter.css maintenance.css noscript.css )
Does anyone knows how can I tell Rails to not compile all partials in css files ?
Thanks for your help !
My application:
- gem 'rails', '4.2.5'
- gem 'sass-rails', '~> 5.0'
- gem 'compass-rails', github: 'Compass/compass-rails', branch: 'master'
- gem 'capistrano', '~> 3.1'
- gem 'spring', '~> 1.3.4'
After spending hours and hours on all the web, I finally discovered the guilty: Froala gem
By looking to the source of the plugin, and the list of precompiled assets, they have a folder called 'plugins' which has the same name as a personal folder. This was meaning my plugins folder with sass partials was also compiled ! The way to fix it was to rename my own 'plugin' folder.
I tried to find the importance of assets pipeline in net but could not get any clarity on it. Why are few gems placed in group :assets and mentioned not required in production in comments part ? I have three small questions to get clarified.
What do we exactly mean by assets PIPELINE ?
Why do we need assets group ?
Why don't we need these gems in production ?
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
Essential reading here: http://guides.rubyonrails.org/asset_pipeline.html
What is the Asset Pipeline?
The asset pipeline provides a framework
to concatenate and minify or compress JavaScript and CSS assets. It
also adds the ability to write these assets in other languages such as
CoffeeScript, Sass and ERB.
The reason for separating these particular gems into their own group, is that they are not needed in production, when rake assets:precompile is run, it creates all of the assets in a form that web browsers can understand (these are stored in the public directory once you've deployed)
e.g. CoffeeScript is compiled into javascript, sass is compiled into CSS. Uglifier just minifies the javascript.
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!
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.
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.