How do I access the styles in a gem from my main application? I created a 'refinerycms-carts' gem and added this file:
refinerycms-carts/app/assets/stylesheets/application.sass
However, when I reload the page and search for the class in application.css in the browser (F12), it does not find it.
I tried adding this line to main app's app/assets/stylesheets/application.css.scss
#import 'refinerycms-carts';
But it gave an error "File to import not found or unreadable: refinerycms-carts."
I also tried naming the file carts.sass but still could not find the class I was referencing.
Yes I'm in development mode. Yes, other changes like controller or models or view are updated and reloaded.
Main app Gemfile: gem 'refinerycms-carts', :path => '../refinerycms-carts'
This is in my refinerycms-carts.gemspec: s.files = Dir["{app,config,db,lib}/**/*"] + ["readme.md"]
This is in my gem Gemfile: gem 'sass-rails'
The gem acts as an Engine.
Rails 3.2.14.
I had to add this in one of my Gem's views:
-content_for :stylesheets, stylesheet_link_tag('refinery/carts')
I also renamed the file to app/assets/stylesheets/refinery/carts.sass. There was already a yield :stylesheets in the app's layout.
When I'm launching my Rails 4 app in development mode – everything works fine, but when I'm trying to precompile assets and then run it in production – my images couldn't be founded on a server.
The problem is in the image request url: it has no fingerprint on the end.
For example, my precompiled image lay at the /assets/image-12rfh98hf734hgf973.png and the request is just the /assets/image.png.
So, the question is how do I write my code inside sass file's to route the correct image?
My gemfile is
gem 'rails', '4.0.1'
gem 'sass-rails', '~> 4.0.0'
gem "compass-rails"
gem 'haml-rails'
I'm trying this code, but it doesn't produce fingerprint in compiled css:
#include background(image-url("baloon_big.png"));
and some variations of image-url, like image-path, image_path etc.
In Rails 3 I hadn't faced this problem, so may be the problem is in the gems.
Thanks in advance.
EDIT
Figured out that problem is only in my work machine – I'm deployed my app to heroku and paths resolving fine (with fingerprints). The question is still open – what's wrong with me (and my computer).
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.
I'm fairly new to Rails but I use sass/compass everyday in non-Rails projects.
I want to use compass plugin gems (e.g. compass-rgbapng) along with compass in the project (Rails 3.2.4). I'm using compass-rails too with gem 'sass-rails ~> 3.2.6' and gem 'sass ~> 3.2.7'.
I added both gems to the Gemfile in the :assets group. I bundle installed, etc. I use the #import call in my sass files to use the gems.
Here is what I get from the server :
File to import not found or unreadable: rgbapng.
Load paths:
Sass::Rails::Importer(/Users/simonwalsh/src/quarterly/app/assets/stylesheets/store/_base.sass)
/Users/simonwalsh/src/quarterly/app/assets/stylesheets
/Users/simonwalsh/src/quarterly/.bundle/ruby/1.9.1/gems/compass->0.12.2/frameworks/blueprint/stylesheets
/Users/simonwalsh/src/quarterly/.bundle/ruby/1.9.1/gems/compass->0.12.2/frameworks/compass/stylesheets
/Users/simonwalsh/src/quarterly/.bundle/ruby/1.9.1/gems/breakpoint-2.0.7/stylesheets
Compass::SpriteImporter
(in /Users/simonwalsh/src/quarterly/app/assets/stylesheets/store/_base.sass)
I did not require the gem anywhere as it is not supposed to be required. Even then, I don't even have a compass.rb or any other config files...
--- EDIT ---
I went to compass-rails doc to try their way of doing that. Here is what I tried :
I added a compass.rb in the initializer with either require 'rgbapng' or config.compass.require 'rgbapng' in it,
I tried the same as above in the application.rb file.
Still nothing works, the app refuses to comply with my #import rgbapng call...
I'm trying to use Susy as the grid element in a project
http://susy.oddbird.net/
FYI I'm also using the following libraries
Compass
Assetic
Symfony (2.x)
Ubuntu (10.4)
When I try to import susy in my sass file
#import "compass/reset"
#import "compass/css3"
#import "susy" <- This line causes a server internal error (500)
I'm sure that this is because compass is unable to locate the susy files to include. Can someone with a successful installation please tell me where these susy files should be located? After installing the compass-susy-plugin using gem installer I can see the following...
ubuntu#ubuntu-desktop:/$ locate susy
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy/bootstrap.rb
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy/clean.rb
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy/config.rb
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy/src
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy/src/_base.scss
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy/src/_defaults.scss
/home/ubuntu/.gem/ruby/1.9.1/gems/compass-0.11.5/examples/susy/src/screen.scss
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy/bootstrap.rb
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy/clean.rb
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy/config.rb
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy/src
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy/src/_base.scss
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy/src/_defaults.scss
/var/lib/gems/1.8/gems/compass-0.11.5/examples/susy/src/screen.scss
It only seems to have saved the susy files into the examples folder - should it also have copied them into the 'frameworks' or libs folder (it hasnt)?
Or is the above correct - in which case how do the 'import' decelerations in the compass file relate to (from the files system POV) the sass files themselves?
BTW: Everything is working great except for this one issue.
P.S
If someone with a rep of over 1500 want to create two new tags then 'Assetic' and 'Susy' should be attached to this post
It looks like the susy gem didn't install properly. I uninstalled/reinstalled and the gem now shows up when I do a gem list as compass-susy-plugin.
Everything now works - I would add that I also needed to add the line require 'susy' to my compass configuration.