I'm using sass-rails and haml-rails gems, so that I can write css file in HAML-sass style.
The thing is when I want to go for production and precompile my stylesheet, the command rake assets:precompile run without error but the generated application.css is empty.
Here it is my Gemfile :
source 'https://rubygems.org'
gem 'rails', '~>3.2'
gem 'pg', '>= 0.14'
gem 'haml-rails' #, '~> 0.3'
group :development, :test do
gem 'factory_girl_rails'
end
group :developpement do
gem 'rspec-rails', '>= 2.11'
gem 'capistrano', '>= 2.12'
gem 'faker', '>= 1.0'
gem 'rvm-capistrano'
end
group :test do
gem 'rspec', '>= 2.11'
gem 'webrat', '>= 0.7'
gem 'spork-rails', '>= 3.2'
end
group :assets do
gem 'sass-rails', '>= 3.2.3'
gem 'coffee-rails', '>= 3.2.1'
gem 'compass-rails', '>= 1.0'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'annotate'
gem 'excel_rails' #, '~> 0.3'
gem 'spreadsheet' #, '~> 0.7'
gem "schema_plus", :git => "git://github.com/lomba/schema_plus.git"
gem 'ar-octopus' #, '~> 0.3'
gem 'squeel' #, '~> 1.0'
gem 'devise' #, '~> 2.1'
gem 'role_model'
gem 'declarative_authorization'
gem 'rails-translate-routes' #, '~> 0.1'
gem 'validates_timeliness' #, '~> 3.0'
Here it is my (empty) app/assets/stylesheets/application.css.sass
/*
* 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.
*
*/
I removed the following commented lines as per recommandation on https://github.com/rails/sass-rails :
*= require_self
*= require_tree .
my css.sass files are stored here :
app/assets/stylesheets/screen.css.sass
app/assets/stylesheets/partials/ (many partials files _*.css.sass referenced by screen.css.sass)
=== UPDATE ===
Please note I'm using COMPASS gem. So mixin and variables need to be shared between stylesheets.
Just in case, this is my app/assets/stylsheets/screen.css.sass file :
// This import applies a global reset to any page that imports this stylesheet.
#import blueprint/reset
// To configure blueprint, edit the partials/base.sass file.
#import partials/base
#import blueprint/interaction
#import blueprint/typography
#import blueprint/grid
#import blueprint/buttons
#import blueprint/utilities
#import compass/layout/grid-background
#import compass/typography/lists/inline-block-list
#import compass/typography/lists/horizontal-list
#import compass/utilities/general/float
#import compass/css3/border-radius
#import compass/css3/box-shadow
#import compass/css3/text-shadow
#import compass/css3/transition
#import partials/opf_mixins_et_functions
#import partials/link_icons
#import partials/typo
#import partials/application
#import partials/affichage_donnees
#import partials/tableau_edition
#import partials/page
#import partials/form
#import partials/feedback
=== UPDATE 2 ===
I realized that my Gemfile will lead me to trouble in production because I put the following Gems in the assets group :
group :assets do
...
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
...
end
Because Production environnement as well needs a javascript interpreter...
So I will move them outside of any group in my Gemfile.
Any advice welcome
You're recommended to remove those two lines but you still need to include yourself your files :
*= require screen
*= require_dir partials/
Do note something, however : this doesn't work like #import - you won't get your mixins and variable shared. Use a real #import for that
OK I solved it with the following solution :
Following the spirit of the last answer, it appears that adding the following line at the end of my /app/assets/styelsheets/application.css.sass solved my issue :
#import screen
Every referenced partial stylesheet by screen.css.sass will then be automatically imported.
My precompiled assets (application.js and application.css) were empty ...
What solved the problem for me :
set the last rails version in Gemfile (3.2.14 for now)
bundle update
bundle install
restart the app touch tmp/restart.txt
Related
So I am building an application & I have added the bootstrap-sass gem. Here is what my gemfile looks like:
gem 'rails', '4.2.6'
gem 'bootstrap-sass'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'bcrypt', '~> 3.1.7'
group :development, :test do
gem 'byebug'
gem 'sqlite3', '1.3.11'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
group :production do
gem 'pg'
end
I my routes folder:
Rails.application.routes.draw do
root 'landing_page#home'
get 'users/new'
end
And I have two stylesheets application.scss & landing_page.scss.
I am simply trying to style my landing page. However, I am unable to get any of the styles from my landing_page.scss to load. I can only get these styles to load if placed in application.scss.
Here is application.scss
#import "bootstrap-sprockets";
#import "bootstrap";
/*
* 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_tree .
*= require_self
*/
#mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
#include box_sizing;
}
body{
background-color: #525252;
}
Anyone know what I am doing wrong? Why is it that sass or just plain css is not being applied when being placed in landing_page.scss?
You want to #import partial to sass file. See http://sass-lang.com/guide to know how partials work.
In your case, you should rename landing_page.scss to _landing_page.scss and do #import landing_page in the application.scss file.
I have tried multiple methods, followed many tutorials but nothing is taking effect on my Rails application. Here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'mysql2'
gem 'paperclip', '~>3.0'
gem 'sass-rails', '~>4.0.0'
gem 'bootstrap-sass', '~>3.2.0.2'
gem 'autoprefixer-rails'
group :doc do
gem 'sdoc', require: false
end
The application.css.scss goes like
/*
* 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.
*
*/
#import "bootstrap-sprockets";
#import "bootstrap";
The application.js file:
// 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
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .
The index.html.erb file:
<div class="posts index">
<h1>Welcome to The Incognito Social Network</h1>
<%=link_to("Say Something!", {:action=> 'new'}, :class=>'action new')%>
<table class="listing" summary="All posts">
<% #posts.each do |post| %>
<tr><td> </td></tr>
<tr>
<td>Post #<%=post.id%> </td>
<td><%=post.text%></td>
<%if post.image_file_name%>
<td>
<%=image_tag post.image.url %>
</td>
<%end%>
</tr>
<tr>
<td><%= link_to("Like", '#', :class=>'action upvote')%></td>
</tr>
<%end%>
</table>
</div>
I have tried writing layout false and #layout false in my controllers. None of it takes effect.
The rails app has no change on it. I tried putting bootstrap code in my index.html.erb files but it does not appear with the Bootstrap style. It appears as if its simple HTML. Anybody knows how to fix this?
Thanks.
As #vanburen already wrote: You have to add the table class to your table tag.
So replace
<table class="listing" summary="All posts">
with
<table class="table listing" summary="All posts">
Now bootstrap should recognize the table and change it's style.
You will find more information in the Docs.
Happy coding :).
All right, so I installed Node.js and restarted my computer. Moreover here is my updated Gemfile
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'mysql2','~> 0.3.11'
gem 'paperclip', '~>3.0'
gem 'sass-rails', '~>4.0.0'
gem 'bootstrap-sass', '~>3.2.0.2'
gem 'autoprefixer-rails'
gem 'acts_as_votable', '~>0.10.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyracer', platforms: :ruby
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
I also figured out that I had to comment out layout false in the controller to get the Bootstrap working. Thank you #Tobias and #vanburen for your help.
Similarly to this issue:
rails: any change to custom.css.scss make the app crash
I have made a change to my custom.css.scss file and all the bootstrap references to colors stopped working. I have manually entered the hex values for these colors now and the app loads, but the classes for my navbar are now not working.
It seems that I have a problem referencing any of the bootstrap classes now for some reason. I also do not understand why making a minor change to a stylesheet has sent my bootstrap styles into a meltdown. I think I must have a setup problem elsewhere.
custom.css.scss:
#import "bootstrap";
/* mixins, variables, etc. */
$grayMediumLight: #eaeaea;
$gray-darker: #222;
$gray-dark: #333;
$gray: #555;
$gray-light: #999;
$gray-lighter: #eee;
Relevant gems
gem 'rails', '4.0.2'
gem 'bootstrap-sass', '2.3.2.0'
gem 'sprockets', '2.11.0'
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
In addition to this, I recently added the bootstrap.css and bootstrap.min.css file to vendor/assets/stylesheets and the same .js files to use a collapsing panel class.
Any help much appreciated.
application.css:
/*
* 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 bootstrap.min
*= require_self
*= require_tree .
*/
UPDATE:
So I removed and then re-included the bootstrap.css and bootstrap.min.css files and the main navbar styles came back to life. The only things that are still not working are the references to colors and the styles for my drop-down list in the navbar.
removing bootstrap files from the vendor/assets/javascript and vendor/assets/stylesheets folders solved this issue for me too.
Hi I have been following Michael Hartl's book for developing rails applications. I have reached the end and I want to start using Bootstrap3 with the app I've developed.
I have followed the instructions on https://github.com/twbs/bootstrap-sass but this has not worked. The gem has installed correctly and I can get it to work on my local environment by changing my application.css --> application.css.scss and adding the import "bootstrap" statement to the file along with having it in custom.css.scss. This doesn't seem right and it doesn't work when I deploy to Heroku either.
The set up I am trying to get work is as follows.
Gem file
source "http://rubygems.org"
ruby '2.0.0'
gem 'rails', '4.0.1'
gem 'sass-rails'
gem 'bootstrap-sass'
gem 'bcrypt-ruby', '3.1.2'
gem 'faker', '1.1.2'
gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem 'sprockets', '2.11.0'
gem 'pg'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess'
end
group :test do
gem 'selenium-webdriver'
gem 'capybara'
gem 'growl'
gem 'factory_girl_rails', '4.2.1'
end
group :doc do
gem 'sdoc', require: false
end
group :production do
gem 'rails_12factor'
end
application.css
/*
* 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_tree .
*/
custom.css.scss
#import "bootstrap";
/*mixins, variables etc. */
$grayMediumLight: #eaeaea;
#mixin box_sizing{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
...
...
Ideally I think I should be changing application.css to .css.scss and having importing bootstrap there without needing it in my custom.css.scss too. This is causing an error when deploying to Heroku, that is saying that application.css is already required.
UPDATE
As per the advice bellow I have removed
Import "bootstrap";
from custom.css.scss and added it to the renamed application.css.scss. This now looks like
#import "bootstrap";
#import "custom";
I cleared the tmp folder using
rake tmp:clear
and then refreshed the page.
Individually importing the css.scss files seems to have solved my problems
I would try the solution you proposed yourself, that is to use application.css.scss instead of application.css and use #import instead of require as mentioned in the rails guide:
If you want to use multiple Sass files, you should generally use the
Sass #import rule instead of these Sprockets directives. Using
Sprockets directives all Sass files exist within their own scope,
making variables or mixins only available within the document they
were defined in. You can do file globbing as well using #import "",
and #import "*/*" to add the whole tree equivalent to how
require_tree works. Check the sass-rails documentation for more info
and important caveats.
check sass-rails' documentation for more.
Try it maybe with
https://github.com/seyhunak/twitter-bootstrap-rails
Please note to choose the bootstrap3 branch, like
gem "twitter-bootstrap-rail", git: "git#github.com:seyhunak/twitter-bootstrap-rails.git", branch: "bootstrap3"
I am not sure what I am missing, but I can only use nesting for in my rails files. I want to be able to use mixins and variables as well.
My gem file is the includes sass:
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
and my css files are name custom.css.scss. What am I missing?
From the Sass doc:
To install Sass in Rails 2, just add config.gem "sass" to
config/environment.rb. In Rails 3, add gem "sass" to your Gemfile
instead. .sass or .scss files should be placed in
public/stylesheets/sass, where they’ll be automatically compiled to
corresponding CSS files in public/stylesheets when needed (the Sass
template directory is customizable… see the Sass reference for
details).
I have to put the css files in a sass folder
I expect you're doing something like *= require_tree . in your application.css.scss file to include your stylesheets.
According to the official documentation, this won't work for mixins and variables:
If you want to use multiple Sass files, you should generally use the
Sass #import rule instead of these Sprockets directives. Using
Sprockets directives all Sass files exist within their own scope,
making variables or mixins only available within the document they
were defined in
It kinda sucks, but you need to include them all individually, if you want the mixins and variables to work. Including them using require compiles more quickly than using import, and should be preferred unless there are shared variables or necessary dependencies.
Example:
//= require navigation
//= require icons
//= require buttons
#import "variables.css.scss";
#import "mixins.css.scss";
#import "something_else.css.scss";