Rake aborts in Rails 3.2.8 - ruby-on-rails

I had create a empty new rails project with a scaffold successfully but when I try rake db:create, it throws me an error: rake aborted! uninitialized constant Rake::DSL.
As other SO post mentioned, I tried setting my Gemfile to gem 'rake', '0.8.7', but rake gives me another error:
You have requested: rake = 0.8.7
The bundle currently has rake locked at 0.9.2.2. Try running bundle
update rake Run bundle install to install missing gems.
Then I did as the message said and update rake and bundle install. Same error.
It is nice and easy experience to develop a project a rails but it is a nightmare porting between ruby versions, rails versions, difference gem and plugin versions..

Try to delete your Gemfile.lock, and type this on your terminal:
bundle install

I had create a empty new rails project with a scaffold successfully but when I try rake db:create, it throws me an error: rake aborted! uninitialized constant Rake::DSL.
for this problem I'd suggest running all rake tasks via bundle exec rake ...

Related

Bundle exec rake versus rails

What is the difference between for example using
rails db:migrate
and
bundle exec rake db:migrate
when using the rails framework? It seems to do the same for me...
Two fold. As of rails 5 you can substitute rails and rake for db:migrate. What you are really changing is adding bundle exec which is telling it to execute the rake from the application's bundler instead of your platform bundler.
For instance, you have bundler v15 on your mac, and bundler v12 on the application. bundle exec rake will use bundler v12, but rake will use bundler v15.
rails db:migrate vs bundle exec rake db:migrate
Internally rails is proxying commands to rake.
See this link

Rails migration error when running migration?

When I do rake db:migrate, I get the following error:
rake aborted!
Gem::LoadError: You have already activated rake 10.2.2, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
How can solve this?
This error is due to the fact that some applications may specify different versions of gems than the ones you have installed.
Try using bundle exec rake db:migrate.
Using bundle exec guarantees that the program is run with the environment specified in the gemfile.
Perhaps:
bundle exec rake db:migrate
There might be other gems in the Gemfile which are dependent on rake 10.2.2, while you are trying to install rake 10.1.0 via your gemfile or explicitly mentioned it. A look into your Gemfile will help.
In case you have specific environment, you may want to run
bundle exec rake db:migrate
to make sure you are running it appropriately.
As per another answer given on this topic, you can also try deleting the Gemfile.lock file and re-running bundle install to regenerate the Gem dependencies.

Rake 0.8.7, rake aborted! uninitialized constant Rake::DSL

I am using 'rake 0.8.7' in my Rails project and yet when I still try either rake routes or bundle exec rake routes I still get
rake aborted!
uninitialized constant Rake::DSL
If I try putting the recommended require 'rake/dsl_definition' in my Rakefile it gives me
rake aborted!
no such file to load -- rake/dsl_definition
So, I'm stuck at how to fix this. I can't run any rake commands...
That error sounds like you are using something in your app that requires a more recent version of rake than 0.8.7. Believe Rake::DSL only showed up in rake 0.9.0.
The most recent version of Rails advertises itself as working with rake as old as 0.8.7. Perhaps it's wrong. More likely you're using some other gem in your project which requires a more recent rake.
Why and how are you using rake 0.8.7 in your project instead of a more recent one? Unless you've locked to rake 0.8.7 in your gemfile (or are using some other gem that insists on 0.8.7), you should be able to run bundle update rake to upgrade to the most recent version of rake.
If you have multiple versions of rake installed, you may have to run bundle exec rake ..., as you noted. But in your project, bundle exec rake still gets you 0.8.7, because for whatever reason that's the version of rake your Gemfile.lock is currently set to -- but your project is using something that wants a more recent version.

bundle exec rake db:migrate causes "can't find executable rake" error

I recently installed Rails 3.1 and now my old Rails 3.0 app won't rake db:migrate. This is what happens when I try to run bundle exec rake db:migrate. I'm on Ubuntu with no RVM
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/shared_helpers.rb:142:in `block in cripple_rubygems': can't find executable rake (Gem::Exception)
from /usr/local/lib/ruby/gems/1.9.1/bin/rake:19:in `<main>'
When I run just rake db:migrate, it outputs:
rake aborted!
You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.8.7. Consider using bundle exec.
(See full trace by running task with --trace)
which rake
/usr/local/bin/rake
Put this in your Gemfile:
gem 'rake' , '>= 0.9.2'
and run bundle update
you need to give more details in what environment you're running this:
which OS?
are you using RVM?
is this a brand new RVM setup per chance?
1) Try to run this:
gem list | rake
what output do you get?
2) If you don't see rake in the output, then do this:
gem install rake
and then try rake db:migrate again
3) If you see rake, but it still doesn't work, then do this:
which rake
what output do you get? it should look something like this:
~/.rvm/gems/ruby-1.9.2-p0/bin/rake

Rake db:create failing in fresh rails 3.1 app

On the 3.1RC, I have created a new app, and when I try to run the db:create job I'm getting this:
[15:38][*********#***********:~/**********/db(master)]$ rake db:create
(in /Users/*********/*********)
rake aborted!
uninitialized constant Rake::DSL
any ideas appreciated.
Use
gem "rake", "0.8.7"
In your gemfile, as stated rake 0.9.0 breaks a few things.

Resources