1

I know this is a common question, but I just started a project with the new Rails 3.1.0 and Ruby 1.9.2 p290

On my first migrations I had already this error and I am not sure why.

Aurelien$ rake db:migrate --trace
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/version.rb:3: warning: already initialized constant NUMBERS
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/version.rb:9: warning: already initialized constant VERSION
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake.rb:26: warning: already initialized constant RAKEVERSION
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/early_time.rb:17: warning: already initialized constant EARLY
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/application.rb:28: warning: already initialized constant DEFAULT_RAKEFILES
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/invocation_chain.rb:49: warning: already initialized constant EMPTY
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/dsl_definition.rb:143: warning: already initialized constant Commands
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_list.rb:44: warning: already initialized constant ARRAY_METHODS
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_list.rb:47: warning: already initialized constant MUST_DEFINE
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_list.rb:51: warning: already initialized constant MUST_NOT_DEFINE
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_list.rb:55: warning: already initialized constant SPECIAL_RETURN
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_list.rb:61: warning: already initialized constant DELEGATING_METHODS
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_list.rb:364: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/file_list.rb:370: warning: already initialized constant DEFAULT_IGNORE_PROCS
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake.rb:64: warning: already initialized constant FileList
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
stack level too deep
/Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/task.rb:162

I also removed the gems and re-tyring with db:reset source 'http://rubygems.org'

gem 'rails', '3.1.0'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

#gem "rspec-rails", :group => [:test, :development]

group :test do
  #gem "factory_girl_rails"
  #gem "capybara"
  #gem "guard-rspec"
  #gem "spork", "> 0.9.0.rc"
  #gem "guard-spork"
end

The rake commands work with bundle exec, but it would be nice to avoid using it.

Thank you in advance for tips and answers.

Aurelien

Zedrian
  • 909
  • 9
  • 29
  • is there a difference between your bundled rake, and your system rake? I'd suggest that's the problem. `rake --version` vs `bundle exec rake --version`. It looks like it's trying to require the rake libraries again, and causing some sort of loop. – Matthew Rudy Oct 03 '11 at 06:56
  • Thanks Matthew, but I get the same version: `Aurelien-Schlumbergers-MacBook-Pro:tchinchine Aurelien$ rake --version rake, version 0.9.2 Aurelien-Schlumbergers-MacBook-Pro:tchinchine Aurelien$ bundle exec rake --version rake, version 0.9.2 ` – Zedrian Oct 03 '11 at 07:06
  • hmm... what if you try creating a new gemset, then bundle install, and try to rake again? Is there some crazy gem overwriting something globally? `rvm gemset create tchinchine && rvm gemset use tchinchine` otherwise, I can't think why `bundle exec rake` would be different from `rake` – Matthew Rudy Oct 03 '11 at 07:11
  • 1
    See the similar question ["RoR: Rake aborted"](http://stackoverflow.com/questions/6727898/rake-aborted-uninitialized-constant-rakedsl-on-heroku) with the reference to a [Yehuda Katz article](http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/) why to use all the time `bundle exec` together with `rake`. – mliebelt Oct 03 '11 at 10:12
  • Thank you Mathew and mliebelt. I guess I will keep using bundle exec, and follow Mr. Katz notes. – Zedrian Oct 03 '11 at 11:22

1 Answers1

5

You should specifically add Rake version >= 0.9.2 in your Gemfile! There was a bug with some Rails 3 versions where you would see strange errors like this when you use an older Rake version.

In your Gemfile:

gem 'rake' , '>= 0.9.2'

I'd also recommend you create a new gemset specifically for your application, e.g.

rvm gemset create yourproject
rvm gemset use yourproject

or:

rvm gemset use yourproject --default

for the new gemset, you might have to add "gem install rake" manually, then run "bundle install"

Using a separate gemset in addition to using your Gemfile is the best way to keep your gem versions in your project stable, and decoupled from other projects.

Tilo
  • 33,354
  • 5
  • 79
  • 106