Ruby on Rails 및 Rake 문제 : 초기화되지 않은 상수 Rake :: DSL
정말 실망스러운 문제가 있습니다. 레이크 가 멍청합니다.
문제가 발생하는 방법은 다음과 같습니다.
$ rails new test_app
$ rails generate scaffold new_scaffold field1:string field2:text
둘 다 잘 작동하지만 내가이 작업을하면
$ rake db:migrate
다음과 같은 오류가 발생합니다.
(in /home/mikhail/test_app)
rake aborted!
uninitialized constant Rake::DSL
/usr/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/home/mikhail/test_app/Rakefile:7:in `<top (required)>'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/bin/rake:31:in `<main>'
인터넷에서 비슷한 / 같은 오류가 있는지 살펴 봤는데 사람들은 그 오류를 보았습니다. 아무도 문제를 해결하지 못하는 것 같습니다!
이 문제를 어떻게 해결합니까?
앞서 DHH 의 트윗 . Rake .9.0은 Rails와 다른 몇 가지를 깨뜨립니다.
gem "rake", "0.8.7"
Gemfile에
나는 이전 답변 직후에 약간의 연구를했습니다 (죄송합니다, 전에해야합니다).
모든 문제는 Rake gem 0.9.2로 해결되었습니다. 다음 단계를 수행했습니다.
- 설치했습니다
gem install rake -v=0.9.2
(0.9.1 보석이있었습니다) - 와 0.9.1을 제거
gem uninstall rake -v=0.9.1
- 로 업데이트
bundle update
그런 다음
db:migrate
경고를 표시WARNING: Global access to Rake DSL methods is deprecated. Please....
Rake 파일에 다음을 추가하여 해결되었습니다.
module ::YourApplicationName class Application include Rake::DSL end end
module ::RakeFileUtils extend Rake::FileUtilsExtend
@databyte에 의해 제안 된 옵션을 생략했습니다 .
그것은 레이크 보석 0.9.2가 잘 작동한다는 것을 의미합니다!
Railstutorial 2 장 (demo_app)을 살펴보고이 문제에 부딪쳤다. 여기에 나열된 다른 모든 답변을 시도했지만이 작업을 수행 할 때까지 작동하지 못했습니다.
위의 Rakefile에 'rake'가 필요합니다.
require 'rake/dsl_definition'
VIA는 어떻게 Heroku가에 초기화되지 않은 일정 레이크 :: DSL의 문제를 해결하기 위해?
또한 모든 파일을 다시 커밋하고 Github와 Heroku로 푸시했습니다.
내가해야 할 일은 사용이었습니다.
gem install rake
0.9.2 버전이 이미 설치되어 있어야합니다.
레이크 보석을 다시 설치하고 그것을 해야 잘 작동 :
gem uninstall rake -v=0.9.2
gem install rake -v=0.9.2
그렇지 않은 경우 Gemfile에 '0.8.7'버전을 지정하십시오.
번 들러를 사용하지 않는 경우 :
sudo gem install rake -v 0.8.7
sudo gem uninstall rake
Then choose to uninstall 0.9.0.
If like me you're stuck on rake 0.8.7, and you're using Rails 3.2.x then railties adds a requirement for Rake::DSL
To solve this, to the top of your Rakefile you should add:
module Rake
module DSL
end
end
I solved the same problem with the following steps:
In Gemfile:
gem 'rake', '0.9.2'
Then ran this on the console:
sudo bundle update rake
Then added the following lines to Rakefile:
require 'rake/dsl_definition'
include Rake::DSL
Rails 3.1.rc1 has been updated. For your own Rakefiles, you can add this before the call to load_tasks.
module ::YourApplicationName
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
https://gist.github.com/4cd2bbe68f98f2f0249f
UPDATE: Also noticed it's already answered here as well: Undefined method 'task' using Rake 0.9.0
I had the same issue and had to use the rake 0.8.7 gem instead of 0.9.0.
I am a Windows XP user and I had the same problem.
I entered gem "rake", "0.8.7" into the gemfile, and then typed the following from the command window.
bundle update rake
This fixed my problem.
- Go to your project path
- Type
bundle install --path=vendor/bundle
- Type
bundle exec rake db:migrate
To start server type bundle exec rails s
. Use bundle exec and you will be sure that you use right gems (required version) for your project. Also I would recommend you to add vendor/bundle
to .gitignore
if you use git
and make alias for bundle exec
. If you use zsh
you can follow this approach
Same as Branstar above - thanks Branstar!
- OS: Windows Vista
- Level: Completely new to Ruby on Rails
- I already had Ruby 1.9.2 installed
I followed the instructions in Running Rails 3 on Windows.
All worked up until the "rake db:migrate" part which gave me the same output as original post.
I ran:
gem install rake
I ran again:
rake db:migrate
Then I was able to start the Ruby on Rails server and had everything in place.
Thanks again Branstar :-)
I feel for you (mikhailvs), it's really frustrating. I have been going crazy for almost one full day. I even uninstalled Ruby and all its dependent files and shutdown my PC, but I still got the same problem.
What I got from the error message is the problem with Rake 0.9.2. It seems like it wasn’t fully installed. So I had to reinstall gem install rake -v=0.9.2
I wasn’t sure if I have rake –v0.9.1 installed. So to make sure I’m safe I tried to remove that old version with gem uninstall rake -v=0.9.1
. But is showed me the error message
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rake`
OK, so I checked all Rake directories on my PC, and found I only had Rake 0.9.2. Then to check if everything went alright, I migrated with rake db:migrate
. And it worked :)
I think I didn’t have Rake 0.9.1 because I clean-installed Ruby (rubyinstaller-1.9.2-p180 - on my Windows 7 system) and all gems as well. In the meantime Rake 0.9.2 wasn’t fully installed.
Uninstalling with "gem uninstall rake" worked for me, I had 2 versions installed, so I jest did a clean reinstall.
"rake db:create", to make sure the database exists and then "rake db:migrate" to seal the deal.
I had the same issue using Rake 0.9.2.2. I solved this problem by using bundle exec.
For Rails 2.3 editing lib/tasks/rspec.rake
like in this commit worked for me:
https://github.com/dchelimsky/rspec-rails/pull/11/files
Install rake 0.8.7 and uninstall 0.9.2.2
$ gem install rake -v 0.8.7
$ gem uninstall rake -v 0.9.2.2
Now use
$ bundle exec rake db:migrate
i think this will help you ;)
Run
bundle exec rake db:migrate
it works for me.
'development' 카테고리의 다른 글
커밋하기 전에 svn에 파일을“추가” (0) | 2020.05.13 |
---|---|
객체가 nullable인지 확인하는 방법? (0) | 2020.05.13 |
__construct 함수는 무엇입니까? (0) | 2020.05.13 |
Makefile 대상에서 Bash 구문을 사용하려면 어떻게해야합니까? (0) | 2020.05.12 |
typedef 고정 길이 배열 (0) | 2020.05.12 |