'sass' in a non thread-safe way - ruby-on-rails

I'm getting these warnings when trying to use sass in Rails 3.1 rc1.
WARN: tilt autoloading 'sass' in a non thread-safe way; explicit require 'sass' suggested.
WARN: tilt autoloading 'sass/plugin' in a non thread-safe way; explicit require 'sass/plugin' suggested.
This is my Gemfile.
gem "rails", "~> 3.1.0.rc1"
gem "haml"
gem "sass"
I've tried to create a file called sass.rb inside the config/initializers containing this code.
require "sass"
Changing the Gemfile to this.
gem "rails", "~> 3.1.0.rc1"
gem "haml"
gem "sass", require: false
But the warnings remains.
Anyone knows how to solve it?
I found the code that is printing the warnings, if that is to any help.

have you tried doing this in Gemfile?
gem "sass", :require => 'sass'
this is an explicit call, without using initializers. by the way consider that you're using a rc1 release.

I had the same problem, and was able to solve it by compiling assets locally before pushing to Heroku as mentioned in the article Rails 3.1+ Asset Pipeline on Heroku Cedar
RAILS_ENV=production bundle exec rake assets:precompile
I also tried Itecedors suggestion which also worked:
While precompiling assets, in Rails 3.1.1 and up, you can prevent initializing
your application and connecting to the database by ensuring that the following
line is in your > config/application.rb:
config.assets.initialize_on_precompile = false

On Heroku I was getting this same error and googling did not help me find the problem, so I thought I would add what I found to this questions since it comes up first when searching.
The problem was NOT this error, it was a smaller error while pushing the code up to Heroku. After the gems are listed these lines got me on the path to the answer:
Running: rake assets:precompile
rake aborted!
Tasks: TOP => environment
(See full trace by running task with --trace)
Precompiling assets failed, enabling runtime asset compilation
Injecting rails31_enable_runtime_asset_compilation
Please see this article for troubleshooting help:
http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
I had just been configuring Redis on Heroku so I knew that the problem had to be something related to those changes. At that URL I found this:
While precompiling assets, in Rails 3.1.1 and up, you can prevent initializing your
application and connecting to the database by ensuring that the following line is in your > config/application.rb:
config.assets.initialize_on_precompile = false
Adding the on_precompile = false line fixed all the errors, including the original one in this question.

Related

Why is this gem not adding rake tasks to a Rails app?

We have a gem which runs via a Rake task. The task is defined in lib/tasks/<namespace>.rake. After reading Rake tasks inside gem not being found I confirmed that the .gemspec includes the file defining the task; there is also a railtie which should be including the tasks as suggested in including rake tasks in gems. And yet our Rails 4.1 application doesn't seem to load the Rake task.
What am I missing?
I just successfully tested your gem and I can see no problem with the rake tasks in it:
I added gem_fresh to the Gemfile and ran bundle, the gem installed
Immediately I could see the rake present in the list of rakes:
$ rake -T outdated
rake gem_fresh:outdated # outdated
Then I updated the railtie.rb file to use the load method to load the rake defined in lib/task/metrics.rake and searched the available rakes again:
# lib/gem_fresh/railtie.rb:
rake_tasks do
namespace :gem_fresh do
desc "outdated"
task :outdated => :environment do
GemFresh::Reporter.new.report
end
end
load "tasks/metrics.rake"
end
$ rake -T outdated
rake gem_fresh:outdated # outdated
rake metrics:outdated_gems # display outdated gem version metrics
So, I can see no problem with your gem. Both methods in railtie (inline rake as well as using the load method) seem to work OK. The only difference I noticed is that I tested this on rails 4.2 but I rather doubt that would make a difference.
Did you put the gem into your Gemfile? If I remove it from there, I indeed see no gem_fresh rakes defined.
The problem was not with the gem, but with the way it was included in the app.
In the Gemfile, this works and includes the rake task:
gem 'gem_fresh'
This works but doesn't include the rake task:
group :development do
gem 'gem_fresh'
end
This seems to be due to how Bundler requires gems in Rails apps. From the documentation:
By default, a Rails generated app calls Bundler.require(:default, Rails.env) in your application.rb, which links the groups in your Gemfile to the Rails environment.
If for some reason that Rails.env argument wasn't evaluating to include the :development group, which seems to be the case when I call rake -T, the gem wouldn't be Bundler.require-d, and the rake tasks wouldn't be loaded.
The fact that it isn't including the :development group seems to be an odd Bundler "gotcha", but at least now I know that moving it to the default group solves the issue and it's not a problem with the gem.
in my case, the project requiring the gem had a rake file, and the gem I was requiring had the same name when I changed the name of the rake file I could see the tasks in the project.
my_gem had lib/tasks/XXXX.rake and my_proj also had lib/tasks/XXXX.rake,
after I changed my_gem XXXX.rake to YYYY.rake I managed to list and use the tasks in YYYY.rake

compass-rails gem not being run in heroku?

My gemfile recently upgraded my compass-rails gem. I started getting the following error (production on heroku only - works fine locally), and have been stuck on it for hours:
Completed 500 Internal Server Error in 14284ms
2012-09-03T20:53:25+00:00 app[web.1]:
2012-09-03T20:53:25+00:00 app[web.1]: ActionView::Template::Error (File to import not found or unreadable: compass/css3.
2012-09-03T20:53:25+00:00 app[web.1]: Load path: Sass::Rails::Importer(/app/app/assets/stylesheets/application.css.scss)
I think part of the problem must lie within the fact the /app/app/ is appearing in the path here - but I dont understand why. When I change the compass config below, to "assets/stylesheets" I still see /app/app/ in the trace error.
production.rb:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
compass.rb
# Require any additional compass plugins here.
project_type = :rails
sass_dir = "app/assets/stylesheets"
Gemfile
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier', '1.2.4'
gem 'yui-compressor', '0.9.6'
gem 'compass-rails'
end
In my application.css.scss file:
#import "compass/css3";
I've been trying every solution I can find without any luck so far
Anything sticking out?
Yes, moving compass-rails out of :assets works but is not an ideal solution.
Checking through the output from the push to heroku I found
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
But it is compiling locally with
RAILS_ENV=production rake assets:precompile
The solution is not to instantiate the DB when precompiling assets. In config/application.rb:
config.assets.initialize_on_precompile = false
See this issue in the compass-rails project:
https://github.com/Compass/compass-rails/issues/19
I upgraded my rails to 3.2+ and ended up moving compass-rails outside of the assets group to make it work. I dont really understand why it works, but it seemed to do the trick.

icon-globe not found after update gem twitter-bootstrap-rails

I'm using twitter-bootstrap-rails gem. Last night I updated my gems, and tried using the icon-globe but all i got was an empty space.
here are my Gemfile:
gem 'jquery-rails'
gem 'therubyracer'
gem 'mongoid'
gem 'bson_ext'
gem 'bson'
gem 'mongo'
gem 'devise'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
I tried rake tmp:clearbut this didn't worked too
I just ran into this the other day as well. I have my Rails servers setup so that I can run multiple Rails apps on the same server under their own suburi. Apparently the asset-path helper in the bootstrap_and_overrides.css.less is not including the relative path for the sprites and instead points the background-image url to /assets instead of /suburi/assets.
Following what I found here: https://github.com/rails/rails/issues/3365 I was able to gather that I needed to do the folllowing when precompiling assets:
RAILS_RELATIVE_URL_ROOT="/suburi" rake assets:precompile
This sets the relative root within the environment when you precompile and everything then works as it should.
The thing that really threw me for a loop was that in development everything worked just fine. As soon as I pushed it to the production server the icons stopped showing up. I kept thinking there was an issue with my server or my code. All along it was just the asset-path helper not including the suburi when I precompiled my assets.
Just set your full suburi path in the RAILS_RELATIVE_URL_ROOT environment variable before running the precompile and it will work.
Update: You can set this variable in the config/application.rb file by adding
config.action_controller.relative_url_root = '/suburi'
This would be the best option as it would not require extra typing when deploying.
You can read about it here:
http://guides.rubyonrails.org/configuring.html#configuring-action-controller
did you try:
bundle exec rake assets:precompile
on your production environment?

Redmine on Heroku - undefined method 'has_key?' for nil:NilClass # email.rake:170

I'm trying to run Redmine on Heroku. Redmine returns a 500 error, presumably because my rake db:migrate fails:
at /app/lib/tasks/email.rake:170
rake aborted!
undefined method `has_key?' for nil:NilClass
The Heroku stack is bamboo-ree-1.8.7. Here's my Gemfile:
source :gemcutter
gem 'i18n', '0.4.2'
gem 'rails', '2.3.11'
gem 'coderay', '0.9.7'
gem 'rack', '1.1.1'
gem 'rake', '0.8.7'
gem 'rubytree'
How do I get heroku rake db:migrate to work?
you should lock your rubytree gem to 0.5.2
try this
gem "rubytree", "0.5.2"
I got this to work by doing two things.
First, I followed some suggestions from http://bayleshanks.com/tips-computer-programming-redmineOnHeroku (specifically I added the suggested line to config/environment.rb and created a blank file called public/plugin_assets/README).
Second, I modified the Gemfile to specify rubytree version 0.6.2, ran bundle install, re-committed the Gemfile.lock into git, and pushed to Heroku.
I'm not sure the earlier steps were necessary, but the database migration finally worked and Redmine is now running.
+1, the above worked for me as well, after satisfying a number of other dependency problems. Ideally, someone should write up a good HOWTO on deploying Heroku, though Ruby/Rails is such a moving target, it would likely only be accurate for a few minutes.

What does error occurred while evaluating nil.dependencies mean?

I'm running ruby on rails v2.2.2 and when I run rake gems I get this error.
$ rake gems --trace
- [I] settingslogic
rake aborted!
You have a nil object when you didn't expect it!
The error occured while evaluating nil.dependencies
/vendor/rails/railities/lib/rails/gem_dependency.rb:77:in `dependencies'
I figured out what was going on. There is a bug in the core rake gems function where it assumed there were specifications for the gem and would error out when it didn't exist for that gem.
Here is the ticket for this issue with a working patch
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1464
Could be a problem with a gem it's trying to load, or your setup of required gems. Check config/environment.rb for any odd-looking config.gem lines, and do an update of all your gems (sudo gem update).
There is a bit more detail here with two alternate workarounds
-add one line to the dependency code in rails
or
-specify gem dependencies before the gem

Resources