ruby on Rails 错误 rake db:create

发布于 2024-11-09 21:51:32 字数 1938 浏览 2 评论 0原文

我一直在 Rails 上使用 ruby​​,没问题,现在每次运行 rake db:create 时都会突然出现以下错误:

C:\>cd xampp

C:\xampp>cd htdocs

C:\xampp\htdocs>cd what

C:\xampp\htdocs\what>rake db:create
rake aborted!
undefined method `task' for #<What::Application:0x20eb1e0>

(See full trace by running task with --trace)

C:\xampp\htdocs\what>

请帮忙???

这是我所有的cmd

   C:\xampp\htdocs\comeon>rake db:create --trace
rake aborted!
undefined method `task' for #<Comeon::Application:0x211fb30>
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:215:
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:i
n `method_missing'
C:/xampp/htdocs/comeon/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `lo
ad'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `lo
ad_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:495:in `r
aw_load_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:78:in `bl
ock in load_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:77:in `lo
ad_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:61:in `bl
ock in run'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:59:in `ru
n'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/bin/rake:31:in `<top (required)>'

C:/Ruby192/bin/rake:19:in `load'
C:/Ruby192/bin/rake:19:in `<main>'

I have been using ruby on rails fine no problem, now suddenly every time I run rake db:create I get the following errors:

C:\>cd xampp

C:\xampp>cd htdocs

C:\xampp\htdocs>cd what

C:\xampp\htdocs\what>rake db:create
rake aborted!
undefined method `task' for #<What::Application:0x20eb1e0>

(See full trace by running task with --trace)

C:\xampp\htdocs\what>

Any help please???

Here is all my cmd

   C:\xampp\htdocs\comeon>rake db:create --trace
rake aborted!
undefined method `task' for #<Comeon::Application:0x211fb30>
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:215:
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:i
n `method_missing'
C:/xampp/htdocs/comeon/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `lo
ad'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `lo
ad_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:495:in `r
aw_load_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:78:in `bl
ock in load_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:77:in `lo
ad_rakefile'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:61:in `bl
ock in run'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/application.rb:59:in `ru
n'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/bin/rake:31:in `<top (required)>'

C:/Ruby192/bin/rake:19:in `load'
C:/Ruby192/bin/rake:19:in `<main>'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2024-11-16 21:51:32

这会对你有所帮助。

gem uninstall rake

gem install rake -v 0.8.7

如果问题仍然存在,请卸载 rake 并安装以

gem uninstall rake
gem install rake

获取更多信息

使用 Rake 0.9 的未定义方法“任务”。 0

This will help you.

gem uninstall rake

gem install rake -v 0.8.7

If Still the problem exists, uninstall rake and install using

gem uninstall rake
gem install rake

for more info

Undefined method 'task' using Rake 0.9.0

渡你暖光 2024-11-16 21:51:32

我遇到了同样的问题,在 git hub 中找到了 Jim Weirich 的帖子,解决了我的问题

https://github.com/jimweirich/rake/issues/33#issuecomment-1213705

这里有两个问题:(1) dimitko 的问题是内置的 rake 命令与新的 gem 的库文件混合在一起。安排你的 $PATH 环境列表,使 rake 的 gem 版本优先于内置版本应该可以解决这个问题。如果您正在使用捆绑程序,您可能还想尝试“bundle exec rake”。

第二个问题(上面的 mjansen401 和 r00k)是新版本的 rake 不再将其 DSL 命令(task、file、desc、import 等)放在 Object 命名空间的根目录中(将它们放在 Object 中意味着每个对象都有一个任务命令,这不是很好。可以通过将 Rake::DSL 模块混合到任何需要命令的模块中来使用 DSL 命令。

在 Rails 更新为支持 Rake 0.9.x 之前,请在调用 Application.load_tasks 之前将以下内容放入项目 Rakefile 中:

class Rails::Application
  include Rake::DSL if defined?(Rake::DSL)
end

请告诉我这些是否适合您。

希望有帮助

I was having the same problem, found a post by Jim Weirich in git hub that solved my problem

https://github.com/jimweirich/rake/issues/33#issuecomment-1213705

Two issues here: (1) dimitko's issue is that the built in rake command is being mixed with the new gem's library files. Arranging your $PATH environment list so that the gem version of rake has precendence over the built-in version should fix that. If you are using bundler, you might also want to try 'bundle exec rake'.

The second issue (mjansen401 and r00k above) is that the new version of rake does not put its DSL commands (task, file, desc, import, etc) in the root of the Object namespace anymore (placing them in Object meant every object has a task command, not very nice . The DSL commands are available by mixing in the Rake::DSL module into any module needing the commands.

Until rails is updated to work with Rake 0.9.x, put the following in your project Rakefile before the call to Application.load_tasks:

class Rails::Application
  include Rake::DSL if defined?(Rake::DSL)
end

Let me know if these work for you.

Hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文