rake assets:precompile aborting - ruby-on-rails

I was able to precompile assets an hour ago, but now the rake task is aborting. I also check it on another app, and it's aborting there too. I had interrupted a push to Heroku rather abruptly, and haven't been able to precompile since then.
bundle exec rake assets:precompile
rake aborted!
undefined method `prerequisites' for nil:NilClass
/Users/mm/Sites/quoraquora/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
Line 7 of the rake file is this code Enki::Application.load_tasks
require File.expand_path('../config/application', __FILE__)
Enki::Application.load_tasks
I also did a bundle update, but it didn't change anything. Prior to trying to run the rake task, I abruptly stopped a push to Heroku because I had forgot to compile the assets. Not sure if that could have caused anything. Interestingly, the application still runs on localhost.
I tried to run bundle exec rake assets:precompile on another app, and I also got an error, albeit a different one that says it can't locate 'uglifier' even though that gem is installed.
bundle exec rake assets:precompile
/Users/mm/.rbenv/versions/1.9.3-p327/bin/ruby /Users/mm/.rbenv/versions/1.9.3-p327/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
cannot load such file -- uglifier
(in /Users/mm/Sites/railshangman/app/assets/javascripts/admin.js)
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/mm/.rbenv/versions...]
Tasks: TOP => assets:precompile
This is the full trace from the first abort. Can anyone explain? The problem seems to be beyond the scope of one specific app, because bundle exec rake assets:precompile was working fine on every app one hour ago.
Macintosh-3:coffeelover mm$ bundle exec rake assets:precompile --trace
rake aborted!
undefined method `prerequisites' for nil:NilClass
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rspec-rails-2.0.1/lib/rspec/rails/tasks/rspec.rake:3:in `<top (required)>'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rspec-rails-2.0.1/lib/rspec-rails.rb:10:in `block in <class:Railtie>'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `instance_exec'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `block in load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `each'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:423:in `block in load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/railties.rb:8:in `each'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/railties.rb:8:in `all'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:423:in `load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:145:in `load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/mm/Sites/coffeelover/Rakefile:7:in `<top (required)>'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:583:in `raw_load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:89:in `block in load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:88:in `load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:72:in `block in run'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/mm/.rbenv/versions/1.9.3-p327/bin/rake:23:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/bin/rake:23:in `<main>'

Try updating your version of rake and rspec-rails
bundle update rspec-rails
bundle update rake

I had to update my version of rspec-rails to 2.6.0 (from 2.0). Strangely, this did not happen automatically if I deleted the gemfile.lock and did bundle update. I had to manually set the version in the Gemfile.

Related

rake db:migrate RoR

well i try to install gem 'omniauth-twitter', create controllers and model this way
rails g controller sessions
rails g model userGem provider:string uid:string name:string
but, in the next step when i try to do a rake db:migrate, throw this error:
rake aborted!
Gem::LoadError: You have already activated rake 10.3.2, but your Gemfile requires rake 10.2.1. Prepending `bundle exec` to your command may solve this.
/home/salinas/.rvm/gems/ruby-2.1.1#global/gems/bundler-1.5.3/lib/bundler/runtime.rb:34:in ` block in setup'
/home/salinas/.rvm/gems/ruby-2.1.1#global/gems/bundler-1.5.3/lib/bundler/runtime.rb:19:in ` setup'
/home/salinas/.rvm/gems/ruby-2.1.1#global/gems/bundler-1.5.3/lib/bundler.rb:119:in `setup'
/home/salinas/.rvm/gems/ruby-2.1.1#global/gems/bundler-1.5.3/lib/bundler/setup.rb:7:in ` <top (required)>'
/home/salinas/blog/config/boot.rb:4:in `<top (required)>'
/home/salinas/blog/config/application.rb:1:in `<top (required)>'
/home/salinas/blog/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/salinas/blog/config/boot.rb:4:in `<top (required)>'
/home/salinas/blog/config/application.rb:1:in `<top (required)>'
/home/salinas/blog/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Any idea how to fix it?
Run the command as:-
bundle exec rake db:migrate
Or remove the rake 10.3.2 as:-
gem uninstall rake
Select the rake-10.3.2 to uninstall.
After removing rake 10.3.2, no need to append bundle exec.

error with rake versioning when running specs in RubyMine; can I manually edit Gemfile.lock

I started getting this error and would like a way to fix it:
You have already activated rake 10.1.1, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
I am running this from within RubyMine. I can see in my Gemfile.lock where it specifies 10.1.0. Can I just manually update my Gemfile.lock to 10.1.1?
If I do:
$gem list
....
rake (10.1.1, 10.1.0, 10.0.4, 0.9.2.2)
So I'm not sure why it isn't just working with 10.1.0?
Here's the full output from RubyMine:
/Users/jt/.rvm/rubies/ruby-1.9.3-p448/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/jt/.rvm/gems/ruby-1.9.3-p448/bin/rake spec
Testing started at 3:15 PM ...
rake aborted!
You have already activated rake 10.1.1, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:33:in `block in setup'
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:19:in `setup'
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
/Users/jt/repos/app/config/boot.rb:6:in `<top (required)>'
/Users/jt/repos/app/config/application.rb:1:in `<top (required)>'
/Users/jt/repos/app/Rakefile:5:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
(See full trace by running task with --trace)
Process finished with exit code 1
You can remove your
Gemfile.lock file
and exec
bundle update

bundle exec rake db:create:all, errors caused by 2 different versions of rake gem, not sure where to go from here

I'm trying to bundle exec rake db:create:all
I found that I have two versions of the rake gem:
rake (10.1.0, 0.9.6)
Author: Jim Weirich
Homepage: http://rake.rubyforge.org
License: MIT
Installed at (10.1.0): /Users/david/.rvm/gems/ruby-2.0.0-p247#global
(0.9.6, default): /Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0
I think there may be an issue with the two different locations of the gems; 10.1 is at #global, and 0.9.6 is not. I think the solution may lay here because...
The trace first looks at the directories in 0.9.6 and then the last two lines look in 10.1:
dn0a158988:portfolio davidngo$ bundle exec rake db:create:all --trace
rake aborted!
cannot load such file -- /Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/config/boot
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/config/application.rb:1:in `require'
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/config/application.rb:1:in `<top (required)>'
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/Rakefile:5:in `require'
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/Rakefile:5:in `<top (required)>'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/rake_module.rb:25:in `load'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/rake_module.rb:25:in `load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:604:in `raw_load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:89:in `block in load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:88:in `load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:72:in `block in run'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:70:in `run'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-0.9.6/bin/rake:37:in `<top (required)>'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247#global/bin/rake:23:in `load'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247#global/bin/rake:23:in `<main>'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
I specified in my Gemfile `gem 'rake', '0.9.6'
I ran bundle update to update the Gemlock file
Thank you in advance -- any help would be appreciated!
Thought: I'm going to try to uninstall the 10.1 version of rake and see if it'll work.
I don't think it's the multiple versions of rake. The bundle exec bit should do the right thing. Are you missing the /config/boot.rb file referred to at /config/application.rb:1?

what does it do by "bundle exec rake db:migrate"?

from my research, bundle exec is responsible for executing a command in the context of a bundle.
anyway, I don't quite understand yet for what it does differently for just the command rake db:migrate comparing with bundle exec rake db:migrate.
for example in my case, I executed the first command, and what I got was the following errors:
$ rake db:migrate
(in c:/rails/rails_projects/soccerweb)
rake aborted!
uninitialized constant Rake::DSL
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8:in `<clas
s:TaskLib>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:6:in `<modu
le:Rake>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:3:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `requ
ire'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `require'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `<top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `block in <class:TestUnitRailtie>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
call'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
block in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `b
lock in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `all'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `l
oad_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:103:
in `load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurabl
e.rb:30:in `method_missing'
c:/rails/rails_projects/soccerweb/Rakefile:7:in `<top (required)>'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
c:/Ruby192/bin/rake:31:in `<main>'
but when I used "bundle exec" preceding that "rake db:migrate" command, everything just worked for me gracefully!
anyone can shed some light on me?
bundle exec rake runs the version of rake which you've specified in your Gemfile. The default version of rake, the one which can be found in your $PATH, might be different than one executed by bundle exec rake.
The problem you've experienced has been covered in a separate question. Your bundle exec rake most probably runs rake 0.8.7 and rake from your $PATH is a newer version which is affected by this problem.
Quoting from man bundle exec:
bundle exec makes a number of changes to the shell environment, then executes the command you specify in full.
(...)
put the directory containing executables (like rails, rspec, rackup) for your bundle on $PATH
Bundler solves gem dependencies for you. You can find read their rationale page for an explanation about their approach.

Problems using rake db:migrate on railstutorial.org chapter 2

I am following the rails tutorial at railstutorial.org
I'm in chapter 2 and tried to migrate the database using rake as per the instructions: "To proceed with the demo application, we first need to migrate the database using Rake (Box 2.1)":
$ rake db:migrate
This did not work and I received the following error:
C:\Users\USER1\rails_project\demo_app>rake db:migrate
(in C:/Users/USER1/rails_project/demo_app)
rake aborted!
uninitialized constant Rake::DSL
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
C:/Users/USER1/rails_project/demo_app/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
C:/Ruby192/bin/rake:31:in `<main>'
How can I resolve this?
This is a problem with the new (just released) version of rake. You can solve it by downgrading rake to 0.8.7. It's the simpler solution for a tutorial. See Rake 0.9.0 'undefined method 'task' ' and answers to that question.
You might add rake 0.8.7 to your Gemfile, like:
gem 'rake', '0.8.7'
And in the terminal you should run with
bundle exec rake db:migrate
And you are ready to follow, i hope this will help you.
I know you would have solved this issue long back but just in case anyone needs to know Rake .9.0 breaks Rails and several other things, you need to either go back to previous version or update the latest one (11.1.2):
gem "rake", "11.1.2"
in your Gemfile.
And then just follow these commands:
$ bundle update rake
Then check the rake with:
$ bundle show rake
And it should show rake 11.1.2.
After this you can successfully run
$ bundle exec rake db:migrate
(PS: hope this helps someone :) )

Resources