I have clean new Rails 4 app with Gemfile:
#default gems
gem 'compass-rails'
gem 'zurb-foundation'
gem 'thin'
with style.scss:
#import "compass";
#import "foundation/variables";
$red: rgb(255,0,1);
$green: rgb(51,153,50);
$body-bg: #F4F4F4;
$body-font-color: #7B7B7B;
$primary-color: #999;
$secondary-color: #0CC;
$dark-color: #393939;
$block-container-border-color: rgb(218,218,218);
$block-container-shadow-color: rgb(208,208,208);
// main background
html{
background:image-url('bckg.jpg');
}
body{
width:1000px;
margin:0 auto;
#include box-shadow(0px 0px 32px -5px #000);
}
And I have this error:
Showing /Users/quatermain/Projects/rails40/app/views/layouts/application.html.erb where line #18 raised:
File to import not found or unreadable: compass.
Load paths:
/Users/quatermain/Projects/rails40/app/assets/images
/Users/quatermain/Projects/rails40/app/assets/javascripts
/Users/quatermain/Projects/rails40/app/assets/stylesheets
/Users/quatermain/Projects/rails40/vendor/assets/javascripts
/Users/quatermain/Projects/rails40/vendor/assets/stylesheets
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/turbolinks-1.2.0/lib/assets/javascripts
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/jquery-rails-3.0.1/vendor/assets/javascripts
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/coffee-rails-4.0.0/lib/assets/javascripts
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/zurb-foundation-4.2.3/scss
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/zurb-foundation-4.2.3/js
(in /Users/quatermain/Projects/rails40/app/assets/stylesheets/style.scss:5)
Is Rails 4 not currently supported by compass-rails?
Compass needs to have some key parts rewritten in order to support Rails 4. There is a temporary branch you can use that has hacked together some support:
'gem "compass-rails", github: "milgner/compass-rails", ref: "1749c06f15dc4b058427e7969810457213647fb8"
You can follow https://github.com/Compass/compass-rails/pull/59 for the latest updates.
Update:
There is now a version in alpha.
gem "compass-rails", "~> 2.0.alpha.0"
Update 2:
compass-rails is no longer in alpha.
Add the following to your Gemfile and type bundle install.
gem "compass-rails", "~> 1.1.2"
I ended up using the alpha version suggested by Sunny Juneja.
But to make it work I had to remove the assets group from my gemfile:
# Not working:
group :assets do # remove me olde line
gem 'sass-rails', '~> 4.0.0'
gem 'compass-rails' # specify me version
end # remove me too, says aye
# Working:
gem 'sass-rails', '~> 4.0.0'
gem 'compass-rails', '~> 2.0.alpha.0'
As of about 18 hours ago, the stable branch of compass-rails supports Rails 4. Remove the version string "2.0.alpha.0" from compass-rails in your Gemfile and run bundle update.
Here's the commit history:
https://github.com/Compass/compass-rails/commits/stable
It appears that as of this time (06/29/2013) compass-rails does not support Rails 4. When I run
rails generate foundation:install
I get the error message below.
Unsupported rails environment for compass
I added all of the compass files to my vendor folder and it worked =), this may not be the preferable option for much longer =(.
Try this:
gem 'sass-rails'
gem 'compass-rails', github: 'Compass/compass-rails'
You should also make sure these are NOT included inside your asset group, since it has been removed from Rails 4.0.
Then remove your Gemfile.lock file and regenerate it using the bundle command.
rm Gemfile.lock
bundle
Related
Description
I'm trying to setup my personal website using GitHub Pages with Jekyll 3.8.5 as described in https://help.github.com/en/github/working-with-github-pages/creating-a-github-pages-site-with-jekyll, but having an issue with the bundler.
Details
Bundle can't find the installed Jekyll 3.8.5
$ bundle exec jekyll 3.8.5 new .
fatal: 'jekyll 3.8.5' could not be found. You may need to install the jekyll-3.8.5 gem or a related gem to be able to use this subcommand.`
Verifying that I actually have jekyll-3.8.5
$ bundle info jekyll
* jekyll (3.8.5)
Summary: A simple, blog aware, static site generator.
Homepage: https://github.com/jekyll/jekyll
Path: /Users/macikportali/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/jekyll-3.8.5
Gemfile (installed with bundle install)
source "https://rubygems.org"
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
# bundle exec jekyll serve
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
# gem "jekyll", "~> 4.0.0"
# gem "jekyll", "~> 3.8.5"
# This is the default theme for new Jekyll sites. You may change this to anything you like.
gem "minima", "~> 2.5"
gem "jekyll-athena"
# Seems this is needed to install a lot of subcommands, see: https://github.com/jekyll/jekyll-compose
gem 'jekyll-compose', group: [:jekyll_plugins]
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
# for jekyll 3.8.5
gem "github-pages", "204", group: :jekyll_plugins
# If you have any plugins, put them here!
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.11"
end
# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do
gem "tzinfo", "~> 1.2"
gem "tzinfo-data"
end
# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.1", :install_if => Gem.win_platform?
Jekyll is used with shims
$ which jekyll
/Users/macikportali/.rbenv/shims/jekyll
My current rbenv version
$ rbenv version
2.7.1 (set by /Users/macikportali/.rbenv/version)
Question
Why bundler cannot see the installed jekyll-3.8.5 gem?
Okey, I think I figured it out. I have two different versions for Jekyll.
$ gem list jekyll
*** LOCAL GEMS ***
jekyll (4.0.1, 3.8.5)
What I did was to add underscores(_) as prefix and postfix to the version, thus, executed
bundle exec jekyll _3.8.5_ new docs
That fixed the problem because I believe this is the convention that gem follows when you have different versions.
Now, I have a different problem which is having 404 page but that's another issue to deal with.
We have a react-rails app. Unfortunately, the app works on local development but not when deployed to heroku. When going to our default path on the app, we get the following error:
ActionView::Template::Error (undefined method 'directory' for #<Sprockets::Manifest:0x007fef13200aa8>)
We've figured out that it happens at this line in our view:
<%= react_component('NavBar', {}, {prerender: true}) %>
A few things about our app:
It uses browserify to compile our js.jsx.
We precompile using RAILS_ENV=production bundle exec rake assets:precompile after deleting the public/assets folder.
Works locally with both rails s and foreman start
We are using boostrap-sprockets. Even when removed, we still have this issue.
Here is our npm dependencies:
"dependencies": {
"browserify": "^10.2.4",
"browserify-incremental": "^1.5.0",
"classnames": "^2.2.3",
"reactify": "^1.1.0"
}
Here is our Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.3'
gem 'rails-api'
gem 'spring', :group => :development
gem 'active_model_serializers', '~> 0.10.0.rc1'
gem 'pg'
gem 'devise'
gem 'puma'
gem 'twitter'
gem 'react-rails', '~> 1.0'
gem 'browserify-rails', '~> 0.9.1'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'sass-rails', '~> 5.0', '>= 5.0.4'
gem 'autoprefixer-rails'
group :test do
gem 'rspec-rails'
gem 'pry'
gem 'faker'
gem 'webmock'
end
group :development, :test do
gem 'factory_girl_rails'
end
group :production do
gem 'uglifier'
gem 'rails_12factor'
gem 'rspec'
end
ruby '2.2.4'
We would appreciate all help.
The solution from hours of searching on StackOverflow and github issues seems to be to remove
//= require react_ujs
from your application.js in your assets folder.
I ran into this same issue just today and followed the suggestions in: https://github.com/reactjs/react-rails/issues/443#issuecomment-180544359. I was still running into an error so for now I modified my heroku configurations (config/environments/staging.rb & config/environments/production.rb) to use
config.assets.compile = true
for now and server-side rendering worked fine. The react-rails folks said they have a pull request completed to fix this issue but I dont think it has been released yet.
Potentially relevant: rake assets:precompile undefined method directory? for nil:NilClass
This is an error that occurs when the Rails asset compiler (Sprockets) cannot find a directory that you've specified as the location of an asset for your project. My suggestion is to make sure that all your assets are being successfully deployed to heroku, and then check that your paths are set up correctly when you reference assets in your project for inclusion in a page.
Also see Eric C's answer pertaining to React-Rails specifically.
There was a bug in react-rails 1.6.0 which should be fixed in 1.6.1
Here's the patch:
https://github.com/reactjs/react-rails/pull/478
If the latest version doesn't work for you, please open an issue on the react-rails repo!
In Rails 3, gems used exclusively to generate assets in the asset pipeline were properly placed in the assets group of the Gemfile:
...
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
end
Now, according to the (still in progress) upgrade documentation:
Rails 4.0 removed the assets group from Gemfile. You'd need to remove that line from your Gemfile when upgrading.
Sure enough, making a new project with RC1 yields a Gemfile with asset-related gems included by default outside of any group:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.rc1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0.rc1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
...
Does this mean these gems will now be bundled in production builds by default? If so, why the change of heart? Is Rails 4 moving towards the dynamic generation of assets in production?
Previously the assets group existed to avoid unintended compilation-on-demand in production. As Rails 4 doesn't behave like that anymore, it made sense to remove the asset group.
This is explained in more detail in the commit that changed that. I extracted some quotes with the actual answer.
Some gems can be needed (in production) like coffee-rails if you are using coffee templates
and the fact that now assets are not precompiled on demand in production anymore.
(not precompiled on demand in production) Means that if you have that gems in production environment in 3.2.x and forget to precompile, Rails will do exactly what it does in development, precompile the assets that was requested. This is not true anymore in Rails 4, so if you don't precompile the assets using the tasks you will get a 404 when the assets are requests.
Rails 4 try to force you to precompile your assets before deployment. You have to precompile your assets with
$ RAILS_ENV=production bundle exec rake assets:precompile
And why?
I found this in Guide:
By default Rails assumes that assets have been precompiled and will be
served as static assets by your web server.
(Source: http://edgeguides.rubyonrails.org/asset_pipeline.html#in-production)
But many time you have to use these 'assets' gems in production... for example, if you use a js.coffee file in your views directory, then Rails needs coffee compiler in production mode as well.
So I guess, the reason of this change is performance improvement... and looks more simple as well. :)
We want coffeescript with AJAX (history), so coffee-rails moves out of the assets group.
sass-rails misbehaves (history), so it moves out of the assets group.
Axe the assets group.
I just installed ruby on my windows 7 computer. I installed rails and sqlite3 with the gem. I then made my app work on local BUT I still seem to have problems with sqlite3. When I try this:
rake db:create
the only thing i get is an error:
Please install the sqlite3 adapter: "gem install activerecord-sqlite3-adapter" (sqlite3
is not part of the bundle. Add it to the GemFile).
I've been doing some digging here and there, and I could make this error go away adding this line to my GemFile:
gem "sqlite3", group: :sqlite3
And i got a new error:
no driver for sqlite3 found
I tried the 'bundle' command and I have both sqlite3 and sqlite3-ruby, I reinstalled everything but the problem won't go away. This is my gemFile, I hope it helps:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#I tried this too, but nothig changes
#gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
gem "sqlite3", group: :sqlite3
# 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'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
I really don't know what to do. It's kind of frustrating, it seems like something is not (obviously) properly working with sqlite3, because fixing one error leads to a new error. How can I possibly fix this problem ?
To everybody who's going to have this problem. What I did to fix it was uninstall everything. I though that maybe since I had an updated version of everything, something might not be working properly, maybe some dependencies were wrongly addressed. So I reinstalled everything following this:
Rails Installer Website
Which will make you install everything you need to run your first RoR app. It might not be up to date but it works just fine. Sqlite3 works perfectly now and that was what I needed. I might try to update every single program later, right now I just need something that is actually working. Thanks to everybody else who tried to help.
I have searched and searched and all I could see was that to use compass with rails 3.1 was to just edit the Gemfile like so:
gem 'compass', :git => 'https://github.com/chriseppstein/compass.git', :branch => 'rails31'
gem 'sass-rails', "~> 3.1.0.rc"
Yes I understand that but what next? Every tutorial I saw said just that, use that certain fork. But I am still having trouble with using compass with rails 3.1.
I did this:
$ compass init rails . --syntax sass
directory ./app/stylesheets/
create ./config/compass.rb
create ./app/stylesheets/screen.sass
create ./app/stylesheets/print.sass
create ./app/stylesheets/ie.sass
And since 3.1 was using assets now, I just transferred all those files to 3.1. Also, I am using compass-960 plugin, so where do I require it? I tried adding a compass.rb with require 960 and require html5-boilerplate and I still keep getting errors:
Error compiling asset application.css:
NoMethodError: undefined method `Error' for Compass:Module
(in /Users/eumir/rails_apps/kiseki/app/assets/stylesheets/screen.sass)
NoMethodError (undefined method `Error' for Compass:Module
(in /Users/eumir/rails_apps/kiseki/app/assets/stylesheets/screen.sass)):
I tried doing compass compile and it gave me this:
$ compass compile
Nothing to compile. If you're trying to start a new project, you have left off the directory argument.
Run "compass -h" to get help.
As I said, I already edited my compass.rb so I am still stumped as to how to go about with this. Any help?
UPDATE: Seems like there is a better way !
Source: http://spin.atomicobject.com/2011/07/12/sass-sprockets-compass-with-rails-3-1/
UPDATE 2(dec 2, 2011): Chris Eppstein, creator of Compass posted this Github Gist of how to integrate Compass with Rails 3.1: https://gist.github.com/1184843
I now prefer this method over mine, as I noticed a great speed improvement at compilation time when using livereload.
MY METHOD:
(I now consider it deprecated, but maybe it can be useful in some cases, so here it is for reference:)
First, in your Gemfile, add:
gem "compass", "~> 0.12.alpha.0"
And don’t forget to execute a
bundle update
Then, in config/application.rb:
config.generators.stylesheet_engine = :sass
Rename application.css.scss to application.css.sass, or create it, and replace its contents by:
#import compass
#import _blueprint
(If you want to keep the new Rails 3.1 manifest code at the beginning of the stylesheet, you’ll have to replace the ‘/* */’ comments by the sass-syntax version ‘//’ at the beginning of each line)
Now, to test if compass and blueprint mixins work, add some code to the same file application.css.sass:
#import compass
#import _blueprint
body
background: black
+linear-gradient(color-stops(white, black))
+column(5)
Run your rails server with
bundle exec rails server
Load your app in a browser, and visit http://localhost:3000/assets/application.css
If everything went well, you should see the compiled code.
Source:
http://blog.pixarea.com/2011/07/using-compass-blueprint-semantic-and-sass-syntax-in-rails-3-1/
The solutions in the other answers are deprecated with the latest version of Compass, v0.12, which requires an adapter to work with a rails app. The Compass author, Chris Eppstein, has put installation instructions on github:
https://github.com/compass/compass-rails
This adapter supports rails versions 2.3 and greater
Peter Gumeson from the compass users groups pointed me to a fix for this:
https://groups.google.com/forum/#!msg/compass-users/mU5HBt8TCIg/2Rt7iSESTSAJ
Here's his message:
Hi gang. This github issue might help out.
https://github.com/sporkd/compass-html5-boilerplate/issues/19
I am pretty much running everything on edge right now. So my gemfile
looks something like this:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sass-rails', '~> 3.1.0.rc2'
gem 'haml', :git => 'git://github.com/nex3/haml.git'
gem 'haml-rails'
gem "compass", :git => "git://github.com/chriseppstein/compass.git", :tag => "0.12.alpha.0"
gem 'compass-html5', :git => 'git://github.com/sporkd/compass-html5.git'
I'm working on the rails generators right now, so it should not be too
far off. But this should at least get you going.
Peter
*changed branches as said by choonkeat
YOu can download the compass directory, dump it in vendor/assets/stylesheets so your directory structure is vendor/assets/stylesheets/compass Then from your main application stylesheets include the compass mixins ass required #include compass/reset;