ある日rakeでエラーになったので対応方法のメモ
rake db:migrateを実行したら以下のエラーが。。というかrake自体がだめっぽい
$ rake -T /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/version.rb:3: warning: already initialized constant NUMBERS /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/version.rb:9: warning: already initialized constant VERSION /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake.rb:26: warning: already initialized constant RAKEVERSION /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/early_time.rb:17: warning: already initialized constant EARLY /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/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/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/invocation_chain.rb:49: warning: already initialized constant EMPTY /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/dsl_definition.rb:143: warning: already initialized constant Commands /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_list.rb:44: warning: already initialized constant ARRAY_METHODS /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_list.rb:47: warning: already initialized constant MUST_DEFINE /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_list.rb:51: warning: already initialized constant MUST_NOT_DEFINE /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_list.rb:55: warning: already initialized constant SPECIAL_RETURN /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_list.rb:61: warning: already initialized constant DELEGATING_METHODS /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_list.rb:364: warning: already initialized constant DEFAULT_IGNORE_PATTERNS /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake/file_list.rb:370: warning: already initialized constant DEFAULT_IGNORE_PROCS /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake.rb:64: warning: already initialized constant FileList /Users/yamazaki/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils rake aborted! stack level too deep (See full trace by running task with --trace)
うーむ。多分、rubyを1.9に変更したのが原因だな
rvmを使っていたので、gemsetを新しく作ることで回避できました。
rvm gemset create hoge rvm gemset use hoge
新しくrailsを入れる
gem install rails
プロジェクトのディレクトリに移動して
bundle install --system
無事解決
$ rake -T rake about # List versions of all Rails frameworks and the environment rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases) rake db:fixtures:load # Load fixtures into the current environment's database. rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false). rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n). rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first) rake db:structure:dump # Dump the database structure to an SQL file rake db:version # Retrieves the current schema version number rake doc:app # Generate docs for the app -- also availble doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-template.rb, TITLE="Custom Title") rake log:clear # Truncates all *.log files in log/ to zero bytes rake middleware # Prints out your Rack middleware stack rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus) rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM rake rails:template # Applies the template supplied by LOCATION=/path/to/template rake rails:update # Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs) rake routes # Print out all defined routes in match order, with names. rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions). rake stats # Report code statistics (KLOCs, etc) from the application rake test # Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins) rake test:recent # Run tests for {:recent=>"test:prepare"} / Test recent changes rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Test changes since last checkin (only Subversion and Git) rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6 rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear) rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids