Ruby on Rails和Rake出现问题

3

我对Rails非常陌生,请原谅我的理解不足。我已经通过RubyGems安装了最新版本的RubyGems、Ruby、Rails、Rake和MySQL等,但是当我开始制作一个基本的Rails应用程序时,出现了以下问题:

Icarus:temporary atg$ rails new people
    ... (output omitted) ...
Icarus:temporary atg$ cd people
Icarus:people atg$ rake db:create
(in /Users/atg/temporary/people)
rake aborted!
uninitialized constant Bundler
/Users/atg/temporary/people/Rakefile:4
(See full trace by running task with --trace)
Icarus:people atg$ rake db:create --trace
(in /Users/atg/temporary/people)
rake aborted!
uninitialized constant Bundler
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
/Users/atg/temporary/people/config/boot.rb:9
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Users/atg/temporary/people/config/application.rb:1
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Users/atg/temporary/people/Rakefile:4
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2017:in `load_rakefile'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2000:in `run'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/Users/atg/.gem/ruby/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

我不知道我做错了什么,而且我对这个领域非常陌生,如果我花费一生的时间来调试它,我也不知道能不能解决问题。有什么想法或指导吗?
非常感谢您的帮助!
3个回答

2

Bundler是Ruby应用程序的新依赖管理系统,并且在新的Rails项目中使用。

# ask rubygems to install bundler
$ gem install bundler

# ask bundler to install your app's dependencies
$ bundle install

# run your app & tasks using bundler
$ bundle exec rake db:create

请将Gemfile的内容粘贴在下面。 - yfeldblum
看起来现在应该可以工作了。可能是Bundler问题(http://github.com/carlhuda/bundler/issues)。由于这些是较新的Rails 3和Bundler版本,现在您已经安装了Bundler并捆绑安装了应用程序的依赖项,请尝试使用仅带有rake db:create而不是带有bundle exec前缀的方式进行操作,看看是否有任何不同。 - yfeldblum
不,我用 rake db:create 得到的结果完全相同。 - adam_0

2

如果这是您第一次接触,我建议从Rails 2.3.8开始。有许多教程和更广泛的支持;3.0有几个重大变化,是比较新的版本。无论如何,您最终都可以从2.3.8升级到3.0.0。


我该如何进行降级呢? - adam_0
看起来我安装了Rails 2.3.8和3.0.0?当我运行gem list时,其中一行显示为rails(3.0.0,2.3.8)。这是否意味着我可以选择要激活哪个版本的Rails? - adam_0

0

我遇到了同样的错误:

rake aborted!
uninitialized constant Bundler

原来这是因为运行cron任务的环境没有像你在shell中那样设置好。.profile和.bash_profile在cron任务之前不会运行。我通过在crontab中设置PATH变量为部署用户的变量来解决了这个问题:
PATH=/opt/nginx/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/Applications/sshfs/bin

你可以通过运行以下命令来检查是否是这个原因导致了你的问题:
which ruby

从 shell 内部和 cron 任务内部运行。如果你得到不同的结果,那就说明 cron 任务没有像你在 shell 中一样运行相同的 Ruby,并且 cron 任务运行的 Ruby 没有安装 Bundler gem。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接