I've got 3.1 application.
At the beginning i'd added
config.assets.enabled = false
not to use pipeline.
Now i've commented this line. restart server.
I've got app\assets\javascripts\application.js
In my layout view I use:
<%= javascript_include_tag "application" %>
my page tries to load "javascripts/application.js" not assets/application.js
What may be wrong in my configuration?
gemfile (unnecessary removed):
gem 'rails', '3.1.1'
gem 'sqlite3'
# Asset template engines
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
Rather than commenting out the line, have you tried leaving it in and making it config.assets.enabled = true instead? It looks like the default value will always be false, so you need to explicitly set it to true.
If you turn the pipeline off then the Rails helpers revert to the old paths to javascript and CSS - in those folders in the /public directory. If you don't want to use the pipeline then you have to use those folders instead, not the assets folder ones.
Dylan is correct - you have to explicitly enable the pipeline, and this is the default for a new generated app.
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 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!
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.