Asset pipeline won't even try to compile SASS - ruby-on-rails-3

My setup is fairly simple default rails 3.2.1 setup. All my .css.sass files are in /app/assets/stylesheets/. I have the sass-rails '~> 3.2.3' gem in :assets group.
There's no application.css, just main.css.sass (used for main layout).
When i issue:
RAILS_ENV=production bundle exec rake assets:precompile
it compiles my coffeescripts and javascripts. There are no error messages in the log. It's like it doesn't even try to compile sass files.
The main.css.sass file header looks like this:
//=depend_on "_globals.css.sass"
#import globals
The _glocals.css.sass exists in the same directory.

James is right and it's one of the possible solutions.
The drawback of adding all files to one manifest file is that all will be precompiled to single file - which isn't always what you want.
In my case I needed separate files (one file for each layout).
Heres how to add new manifest files:
config.assets.precompile += %w( file1.css file2.css )
You don't need to have actual file1.css, if you have file1.css.sass it will be precompiled.

I think sass needs a manifest file and by default that's application.css for a rails 3.2 app. So creating application.css and //= require 'main' might dove your problem.

Related

Excluding files from assets:precompile in rails

I use codekit for writing less which it then converts to css automatically.
I don't want rails to convert my less files to css, I rather codekit do it.
if I precompile the assets via
rake assets:precompile
I get
rake aborted!
cannot load such file -- less
How do I exclude a specific folder/file types from precompiling? (all my less files are in app/assets/stylesheets/less and the css (which I do want to be precompiled) are in app/assets/stylesheets/css
update
deleting application.less solves this but how do I excluding it from processing in the first place?
From the Asset Pipeline guide:
The default matcher for compiling files includes application.js,
application.css and all non-JS/CSS files (i.e., .coffee and .scss
files are not automatically included as they compile to JS/CSS):
[ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, /application.(css|js)$/ ]
If you have other manifests or individual stylesheets and JavaScript
files to include, you can add them to the precompile array:
config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
So, I would say that your solution is to modify config.assets.precompile to exclude .less files. Maybe something like this (in a suitable environment file, like config/environments/production.rb):
config.assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css', '.less']) }, /application.(css|js)$/ ]
If your directory structure under the app/assets folder is so:
application.css
/css
(generated by code kit)
|...home.css
|...index.css
/less
|...home.less (assuming this is the extension)
|...index.less
Then, in your application.css file, there must be a directive that says *= require_tree . This tells rails to scan all the files/directories and try to compile all the files into one css file.
Change this to *= require_directory ./css and it will load the files under the css directory for compilation.

#import "compass" breaking in asset pipeline rails 3.2.1

I have an application.sass inside app/assets/stylesheets and it has in it:
#import "compass"
When I attempt to launch my development webserver, I get:
Error compiling CSS Asset
Sass::SyntaxError: File to import not found or unreadable: compass.
I am using compass-rails-1.0.0.rc.2 with compass-0.12.rc.1
This probably isn't your problem, but I just ran across the same error message and spent WAY too long trying different versions of compass/compass-rails, thinking it wasn't my fault.
The problem turned out to be that my application.css file wasn't getting run through the sass preprocessor. So I renamed it to application.css.scss and bang! Yours is named .sass, you could check by renaming it to .css.sass, or .css.scss (just to test) and see if you get different results.
Are you upgrading from a pre-asset pipeline version of Rails (e.g. 3.0)? Please make sure that you are requiring the assets group when initializing bundler in your application.rb.
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
Otherwise, for compass to work in development, compass-rails and sass-rails must be outside of the assets group in your Gemfile.

rails 3 sass compiling

Hello I have one question I have my file main.scss which is in public/stylesheets/scss. In documentation is written:
By default, .sass and .scss files are
placed in public/stylesheets/sass
(this can be customized with the
:template_location option). Then,
whenever necessary, they’re compiled
into corresponding CSS files in
public/stylesheets. For instance,
public/stylesheets/sass/main.scss
would be compiled to
public/stylesheets/main.css.
I have in my gemfile gem 'haml'
And from my view I do sth like this
= stylesheet_link_tag 'main'
And the file is not found when I check the source(there is a file with with information about routing error). I guess that compiling it by hand it is not way to go so how I can make compile scss file to public/stylesheets automatic? What mean in documentation that they are compiled when necessary?
Thanks in advance
Put your .sass or .scss files in public/stylesheets/sass, not public/stylesheets/scss. Then the stylesheets should automatically generate whenever you change the corresponding sass/scss file. The generated stylesheets end up in public/stylesheets/.
Renaming the folder should make it all work.
EDIT: it looks like Rails 3.1 is going to be not only including SASS by default, but it will also be moving most of the stuff found in the public folder to the app folder... so this answer will only apply to versions of rails before 3.1.

Rails Engine - Gems dependencies, how to load them into the application?

I'm doing an engine here, it works alright in stand alone.
When I transform it into a gem, and load it inside another application, I get a lot of undefined errors, coming from my engine gem's dependecies.
Here is the gemspec:
s.add_dependency('paperclip')
s.add_dependency('jquery-rails')
s.add_dependency('rails3-jquery-autocomplete')
s.add_dependency('remotipart')
s.add_dependency('cancan')
In the application, when I do a bundle install, it lists all these dependencies, but as i run the application I receive a lot of undefined methods errors (has_attachment from paperclip for example). It seems that the application doesn't load the engines dependencies.
Is this the default behavior? Can I change it?
Same thing happened with a plugin inside the engine.
If I insert by hand those gems, in the application Gemfile, all works...
Include them in your gemfile and run bundle install. Then require them in your lib/<your_engine>/engine.rb file. Don't forget to require rubygems
require 'rubygems'
require 'paperclip'
require 'jquery-rails'
require 'rails3-jquery-autocomplete'
require 'remotipart'
require 'cancan'
Then in your host app (The app where you included your gem) run bundle install/ bundle update (bundle update did the trick for me) and then everything should work perfectly. You can also test this by starting the console in your host app and just type the module name e.g.
Loading development environment (Rails 3.0.3)
irb(main):001:0> Paperclip
=> Paperclip
Hope this helps
You can require them manually like Daniel posted, and you can also require them automatically. You need to add dependencies in 3 files:
yourengine.gemspec
s.add_dependency "rails", '4.1.0'
s.add_dependency "sqlite3"
Gemfile
# Imports dependencies from yourengine.gemspec
gemspec
lib/yourengine.rb
# requires all dependencies
Gem.loaded_specs['yourengine'].dependencies.each do |d|
require d.name
end
require 'yourengine/engine'
module Yourengine
end
Update: It's a simplistic demonstration of how to require the dependencies. You should test it and filter unwanted items, for example: require d.name unless d.type == :development (thx #imsinu9)
from paperclip's README :
For Non-Rails usage:
class ModuleName < ActiveRecord::Base
include Paperclip::Glue
...
end
I had the same issue and that fixed it for me.
You must add the gem file to both the .gemspec file, and your engine.rb file.
In the .gemspec file it would be like:
s.add_dependency "kaminari", "0.16.1"
In the engine.rb file at the top add:
require "kaminari"
I think you also need to add the gem to the rails engine Gemfile and bundle install, but I'm not certain if you need it there.
At the time being (Rails 3.1 and above I think), you shouldn't have do declare any gems in the test/dummy/Gemfile anymore:
Quote from test/dummy/Gemfile (generated using rails plugin new my_engine --full):
Declare your gem's dependencies in simple_view_helpers.gemspec.
Bundler will treat runtime dependencies like base dependencies, and
development dependencies will be added by default to the :development group.
Declare any dependencies that are still in development here instead of in
your gemspec. These might include edge Rails or gems from your path or
Git. Remember to move these dependencies to your gemspec before releasing
your gem to rubygems.org.
You really shouldn't need them on the Gemsec, and they should be loaded. When you say "here is the gemspec", you are surrounding it with Gem::Specification.new do |s| or something to that effect, right?
You can include all gems for the environment with a simple bundler command:
Bundler.require(*Rails.groups)
You could add this to an config/initializer.

Getting SASS to work with Rails 3

I am trying to get SASS to work with Rails 3.
I have added gem 'haml' to my Gemfile (and ran bundle install) and I have added a styles.scss to my public/ directory, but it does not seem to be working. Can someone help me out? Thanks!
By default, Sass expects sass/scss files to go in public/stylesheets/sass, which are then compiled into css files in public. You can change this path by setting Sass::Plugin.options[:template_location] in your config, though.